summaryrefslogtreecommitdiffstats
path: root/pym
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2009-03-11 06:29:08 +0000
committerZac Medico <zmedico@gentoo.org>2009-03-11 06:29:08 +0000
commit9a34060f3c0d7a62ceeb8ecb74dbb4f5a34d6b3d (patch)
tree41b305fa541fde8737b5042c4bdbebef833c2f40 /pym
parent6e24129a3dda10fe300c6f3631ed5bc31e8fb601 (diff)
downloadportage-9a34060f3c0d7a62ceeb8ecb74dbb4f5a34d6b3d.tar.gz
portage-9a34060f3c0d7a62ceeb8ecb74dbb4f5a34d6b3d.tar.bz2
portage-9a34060f3c0d7a62ceeb8ecb74dbb4f5a34d6b3d.zip
Make Atom instances consume less memory by implementing str methods at the
class level instead of referencing bound str methods. (trunk r12730) svn path=/main/branches/2.1.6/; revision=12979
Diffstat (limited to 'pym')
-rw-r--r--pym/portage/dep.py70
1 files changed, 61 insertions, 9 deletions
diff --git a/pym/portage/dep.py b/pym/portage/dep.py
index 22fa8bf56..4a9d85e3c 100644
--- a/pym/portage/dep.py
+++ b/pym/portage/dep.py
@@ -506,14 +506,8 @@ class Atom(object):
__metaclass__ = _AtomCache
_atoms = weakref.WeakValueDictionary()
- _str_methods = ("endswith", "find", "index", "lstrip", "replace",
- "startswith", "split", "strip",
- "rindex", "rfind", "rstrip", "__getitem__",
- "__eq__", "__hash__", "__len__", "__lt__",
- "__ne__", "__repr__", "__str__")
-
__slots__ = ("__weakref__", "blocker", "cp", "cpv", "operator",
- "slot", "use") + _str_methods
+ "slot", "use", "_str")
class _blocker(object):
__slots__ = ("overlap",)
@@ -531,8 +525,7 @@ class Atom(object):
if not isvalidatom(s, allow_blockers=True):
raise InvalidAtom(s)
obj_setattr = object.__setattr__
- for x in self._str_methods:
- obj_setattr(self, x, getattr(s, x))
+ obj_setattr(self, '_str', s)
blocker = "!" == s[:1]
if blocker:
@@ -561,6 +554,65 @@ class Atom(object):
raise AttributeError("Atom instances are immutable",
self.__class__, name, value)
+ # Implement some common str methods.
+
+ def __eq__(self, other):
+ return self._str == other
+
+ def __getitem__(self, key):
+ return self._str[key]
+
+ def __hash__(self):
+ return hash(self._str)
+
+ def __len__(self):
+ return len(self._str)
+
+ def __lt__(self, other):
+ return self._str < other
+
+ def __ne__(self, other):
+ return self._str != other
+
+ def __repr__(self):
+ return repr(self._str)
+
+ def __str__(self):
+ return str(self._str)
+
+ def endswith(self, *pargs, **kargs):
+ return self._str.endswith(*pargs, **kargs)
+
+ def find(self, *pargs, **kargs):
+ return self._str.find(*pargs, **kargs)
+
+ def index(self, *pargs, **kargs):
+ return self._str.index(*pargs, **kargs)
+
+ def lstrip(self, *pargs, **kargs):
+ return self._str.lstrip(*pargs, **kargs)
+
+ def replace(self, *pargs, **kargs):
+ return self._str.replace(*pargs, **kargs)
+
+ def startswith(self, *pargs, **kargs):
+ return self._str.startswith(*pargs, **kargs)
+
+ def split(self, *pargs, **kargs):
+ return self._str.split(*pargs, **kargs)
+
+ def strip(self, *pargs, **kargs):
+ return self._str.strip(*pargs, **kargs)
+
+ def rindex(self, *pargs, **kargs):
+ return self._str.rindex(*pargs, **kargs)
+
+ def rfind(self, *pargs, **kargs):
+ return self._str.rfind(*pargs, **kargs)
+
+ def rstrip(self, *pargs, **kargs):
+ return self._str.rstrip(*pargs, **kargs)
+
def get_operator(mydep):
"""
Return the operator used in a depstring.