diff options
| author | Jason Madden <jamadden@gmail.com> | 2020-01-22 09:32:06 -0600 |
|---|---|---|
| committer | Jason Madden <jamadden@gmail.com> | 2020-01-22 09:32:06 -0600 |
| commit | 3cc593ed15c08e09f47cd9a186bd1cd33c1cc148 (patch) | |
| tree | 2fff330a718986fa6795de52aee6d0b854fa4dfa /src/zope/interface/declarations.py | |
| parent | b928f8a53cb299f72ff60fc8e622b8e41cabad12 (diff) | |
| download | zope-interface-c-opts-members.tar.gz | |
Use tp_members in SpecificationBase and ClassProvidesBase.c-opts-members
Instead of storing 1 and 2 attributes, respectively, in __dict__. This lets us eliminate inst_attr and its use of an undocumented API.
It also helps reign in the size of these objects. Before, on CPython 8, a ClassProvides object that subclasses both SpecificationBase and ClassProvidesBase required 408 bytes: 48 for the object, 360 for the dict.
Now it requires 72 + 232 = 304.
With a bit of work on defining __slots__ in Python, that can be brought much lower still, I think.
zope.security tests pass with this installed.
Diffstat (limited to 'src/zope/interface/declarations.py')
| -rw-r--r-- | src/zope/interface/declarations.py | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/src/zope/interface/declarations.py b/src/zope/interface/declarations.py index 100417f..991fb95 100644 --- a/src/zope/interface/declarations.py +++ b/src/zope/interface/declarations.py @@ -626,6 +626,8 @@ def noLongerProvides(object, interface): @_use_c_impl class ClassProvidesBase(object): + # In C, this extends SpecificationBase, so its kind of weird here that it + # doesn't. def __get__(self, inst, cls): if cls is self._cls: @@ -648,6 +650,7 @@ class ClassProvides(Declaration, ClassProvidesBase): we can get declarations for objects without instance-specific interfaces a bit quicker. """ + def __init__(self, cls, metacls, *interfaces): self._cls = cls self._implements = implementedBy(cls) |
