From a2b66e943b29d9a7a8c6bb14fd569fb5b402f55c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Wed, 2 Oct 2019 22:45:12 -0700 Subject: [PATCH] fix: Big speed improvment when loading MISPEvent 1. `properties` is a list comprehension 2. Massively reduce the amount of calls to `properties` --- pymisp/abstract.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/pymisp/abstract.py b/pymisp/abstract.py index c85ef3b..39c6165 100644 --- a/pymisp/abstract.py +++ b/pymisp/abstract.py @@ -107,12 +107,7 @@ class AbstractMISP(MutableMapping): """All the class public properties that will be dumped in the dictionary, and the JSON export. Note: all the properties starting with a `_` (private), or listed in __not_jsonable will be skipped. """ - to_return = [] - for prop, value in vars(self).items(): - if prop.startswith('_') or prop in self.__not_jsonable: - continue - to_return.append(prop) - return to_return + return [k for k in vars(self).keys() if not (k[0] == '_' or k in self.__not_jsonable)] def from_dict(self, **kwargs): """Loading all the parameters as class properties, if they aren't `None`. @@ -216,8 +211,9 @@ class AbstractMISP(MutableMapping): raise Exception('edited can only be True or False') def __setattr__(self, name, value): - if name in self.properties: - self.__edited = True + if name != '_AbstractMISP__edited': + if not self.__edited and name in self.properties: + self.__edited = True super(AbstractMISP, self).__setattr__(name, value) def _datetime_to_timestamp(self, d):