summaryrefslogtreecommitdiff
path: root/pym
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2008-06-20 16:47:45 +0000
committerZac Medico <zmedico@gentoo.org>2008-06-20 16:47:45 +0000
commit8918b6b0b3ab35181d23d4d760a6f48574c6c869 (patch)
tree0fa329e72118f1571bb4e1486b6b88bea10acd54 /pym
parentUse a metaclass to cache Atom instances transparently. This should improve (diff)
downloadportage-idfetch-8918b6b0b3ab35181d23d4d760a6f48574c6c869.tar.gz
portage-idfetch-8918b6b0b3ab35181d23d4d760a6f48574c6c869.tar.bz2
portage-idfetch-8918b6b0b3ab35181d23d4d760a6f48574c6c869.zip
Make the Atom cache dict private and add a docstring for _AtomCache.
svn path=/main/trunk/; revision=10742
Diffstat (limited to 'pym')
-rw-r--r--pym/portage/dep.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/pym/portage/dep.py b/pym/portage/dep.py
index a1908276..bd9b1967 100644
--- a/pym/portage/dep.py
+++ b/pym/portage/dep.py
@@ -393,12 +393,15 @@ class _use_dep(object):
return _use_dep(tokens)
class _AtomCache(type):
- atoms = {}
+ """
+ Cache Atom instances from constructor calls and reuse
+ identical instances when available.
+ """
def __call__(cls, s):
- instance = cls.atoms.get(s)
+ instance = cls._atoms.get(s)
if instance is None:
instance = super(_AtomCache, cls).__call__(s)
- cls.atoms[s] = instance
+ cls._atoms[s] = instance
return instance
class Atom(object):
@@ -409,6 +412,7 @@ class Atom(object):
"""
__metaclass__ = _AtomCache
+ _atoms = {}
_str_methods = ("endswith", "find", "index", "lstrip", "replace",
"startswith", "strip", "rindex", "rfind", "rstrip", "__getitem__",