Optimize the _set_properties_from_keyword_args() function.
We do not need to check if the attribute exist to raise an exception, setattr() yet raise a well formatted expection in case of failure. This way we avoid a dir() call and an IN check in a hot path. The only drawback is that this change the raised exception in the case an attr not exist, from AssertionError to AttributeError... I hope none was using that eception explicitly.
This commit is contained in:
parent
da1807c379
commit
d3f98802b0
|
@ -237,12 +237,9 @@ cdef class Eo(object):
|
|||
return 1
|
||||
|
||||
cdef int _set_properties_from_keyword_args(self, dict kwargs) except 0:
|
||||
if not kwargs:
|
||||
return 1
|
||||
cdef list cls_list = dir(self)
|
||||
for k, v in kwargs.items():
|
||||
assert k in cls_list, "%s has no attribute with the name %s." % (self, k)
|
||||
setattr(self, k, v)
|
||||
if kwargs:
|
||||
for k, v in kwargs.items():
|
||||
setattr(self, k, v)
|
||||
return 1
|
||||
|
||||
def delete(self):
|
||||
|
|
Loading…
Reference in New Issue