Re: SVN: zope.interface/branches/jinty-mem/src/zope/interface/interface.py Improve CPU performance of previous memory optimization
Tres Seaver <[email protected]>
| Newsgroups | gmane.comp.web.zope.devel |
|---|---|
| Message-ID | <[email protected]> |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 11/09/2010 08:26 AM, Wichert Akkerman wrote:
> On 11/9/10 14:22 , Brian Sutherland wrote:
>> Log message for revision 118295:
>> Improve CPU performance of previous memory optimization
>>
>> Changed:
>> U zope.interface/branches/jinty-mem/src/zope/interface/interface.py
>>
>> -=-
>> Modified: zope.interface/branches/jinty-mem/src/zope/interface/interface.py
>> ===================================================================
>> --- zope.interface/branches/jinty-mem/src/zope/interface/interface.py 2010-11-09 08:31:37 UTC (rev 118294)
>> +++ zope.interface/branches/jinty-mem/src/zope/interface/interface.py 2010-11-09 13:22:27 UTC (rev 118295)
>> @@ -51,6 +51,7 @@
>> # infrastructure in place.
>> #
>> #implements(IElement)
>> + __tagged_values = None
>>
>> def __init__(self, __name__, __doc__=''):
>> """Create an 'attribute' description
>> @@ -72,22 +73,27 @@
>>
>> def getTaggedValue(self, tag):
>> """ Returns the value associated with 'tag'. """
>> - return getattr(self, '_Element__tagged_values', {})[tag]
>> + if self.__tagged_values is None:
>> + return default
>> + return self.__tagged_values[tag]
>
> You can even optimise this further:
>
> tv = self.__tagged_values
> if tv is None:
> return default
> return tv[tv]
>
> that avoids a second attribute lookup. You may also want to benchmark
> that versus using a __tagged_values={} on the class and doing a simple
> return self.__tagged_values.get(tag, default_
- -1: mutable class defaults are a bug magnet.
Tres.
- --
===================================================================
Tres Seaver +1 540-429-0999 [email protected]
Palladion Software "Excellence by Design" http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkzZlFUACgkQ+gerLs4ltQ5ZYQCfRyDUGofCMiER447yJjBeEduu
E5IAniZu6SbOmYZC0XJt/4WeXOY2u5oD
=cNXP
-----END PGP SIGNATURE-----
_______________________________________________
Zope-Dev maillist - [email protected]
https://mail.zope.org/mailman/listinfo/zope-dev
** No cross posts or HTML encoding! **
(Related lists -
https://mail.zope.org/mailman/listinfo/zope-announce
https://mail.zope.org/mailman/listinfo/zope )