From dc579385ad670300a755485684888da51d4d9b38 Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Thu, 24 Oct 2024 23:37:17 +0100 Subject: [PATCH] Tweak for better performance --- gramps/gen/lib/baseobj.py | 13 +++++++------ gramps/gen/lib/serialize.py | 1 + 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/gramps/gen/lib/baseobj.py b/gramps/gen/lib/baseobj.py index 7e4734d6ef..5e67d3d252 100644 --- a/gramps/gen/lib/baseobj.py +++ b/gramps/gen/lib/baseobj.py @@ -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): @@ -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): """ diff --git a/gramps/gen/lib/serialize.py b/gramps/gen/lib/serialize.py index f840ed13d5..79ed49890a 100644 --- a/gramps/gen/lib/serialize.py +++ b/gramps/gen/lib/serialize.py @@ -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