Skip to content

Commit

Permalink
Tweak for better performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick-Hall committed Oct 24, 2024
1 parent 56aa644 commit dc57938
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
13 changes: 7 additions & 6 deletions gramps/gen/lib/baseobj.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,12 @@ def get_object_state(self):
of the object or None if the object is empty.
:rtype: dict
"""
attr_dict = {"_class": self.__class__.__name__}
for key, value in self.__dict__.items():
if not key.startswith("_"):
attr_dict[key] = value
attr_dict = dict(
(key, value)
for key, value in self.__dict__.items()
if not key.startswith("_")
)
attr_dict["_class"] = self.__class__.__name__
return attr_dict

def set_object_state(self, attr_dict):
Expand All @@ -97,8 +99,7 @@ def set_object_state(self, attr_dict):
:type attr_dict: dict
"""
for key, value in attr_dict.items():
if key != "_class":
setattr(self, key, value)
setattr(self, key, value)

def matches_string(self, pattern, case_sensitive=False):
"""
Expand Down
1 change: 1 addition & 0 deletions gramps/gen/lib/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

def __object_hook(obj_dict):
obj = getattr(lib, obj_dict["_class"])()
del obj_dict["_class"]
obj.set_object_state(obj_dict)
return obj

Expand Down

0 comments on commit dc57938

Please sign in to comment.