| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
There was a problem hiding this comment.
Does it affect three-argument getattr()?
Sorry, something went wrong.
| // gh-157840: When using hasattr(), slot members without assigned values | ||
| // need to go through __get__(), which involves creating an AttributeError | ||
| // object (which is really slow). There's no way to supply "suppress" | ||
| // to the tp_descr_get() function, so we just special-case member | ||
| // descriptors here to improve performance. |
There was a problem hiding this comment.
Could you please simplify the comment, leaving the substantial part?
Sorry, something went wrong.
There was a problem hiding this comment.
Done
Sorry, something went wrong.
Yeah -- performance there is also improved by this PR. |
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM. 👍
Two nits.
Sorry, something went wrong.
| if (suppress && Py_IS_TYPE(descr, &PyMemberDescr_Type)) { | ||
| PyMemberDef *member = ((PyMemberDescrObject *)descr)->d_member; | ||
| if (member->type == Py_T_OBJECT_EX | ||
| && !(member->flags & Py_AUDIT_READ) && |
There was a problem hiding this comment.
Inconsistent formatting. && after and before line split.
Sorry, something went wrong.
| @@ -0,0 +1,2 @@ | |||
| Speed up calls to :func:`hasattr` for unassigned attributes in an object's | |||
There was a problem hiding this comment.
Mention also getattr.
Sorry, something went wrong.
|
Thanks for the review! |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Before this PR:
$ ./python -m timeit -s 'class Test: __slots__ = ("x",)' -s 't = Test()' 'hasattr(t,"x")' --number 100000000 100000000 loops, best of 5: 192 nsec per loopAfter:
$ ./python -m timeit -s 'class Test: __slots__ = ("x",)' -s 't = Test()' 'hasattr(t,"x")' --number 100000000 100000000 loops, best of 5: 30.8 nsec per loop