1 |
Author: zmedico |
2 |
Date: 2008-06-20 16:18:46 +0000 (Fri, 20 Jun 2008) |
3 |
New Revision: 10741 |
4 |
|
5 |
Modified: |
6 |
main/trunk/pym/portage/dep.py |
7 |
Log: |
8 |
Use a metaclass to cache Atom instances transparently. This should improve |
9 |
performance and conserve memory in cases when the same atom is more than |
10 |
once. |
11 |
|
12 |
|
13 |
Modified: main/trunk/pym/portage/dep.py |
14 |
=================================================================== |
15 |
--- main/trunk/pym/portage/dep.py 2008-06-20 14:37:49 UTC (rev 10740) |
16 |
+++ main/trunk/pym/portage/dep.py 2008-06-20 16:18:46 UTC (rev 10741) |
17 |
@@ -392,6 +392,15 @@ |
18 |
tokens.extend(self.conditional_disabled.difference(use)) |
19 |
return _use_dep(tokens) |
20 |
|
21 |
+class _AtomCache(type): |
22 |
+ atoms = {} |
23 |
+ def __call__(cls, s): |
24 |
+ instance = cls.atoms.get(s) |
25 |
+ if instance is None: |
26 |
+ instance = super(_AtomCache, cls).__call__(s) |
27 |
+ cls.atoms[s] = instance |
28 |
+ return instance |
29 |
+ |
30 |
class Atom(object): |
31 |
|
32 |
""" |
33 |
@@ -399,6 +408,8 @@ |
34 |
class emulates most of the str methods that are useful with atoms. |
35 |
""" |
36 |
|
37 |
+ __metaclass__ = _AtomCache |
38 |
+ |
39 |
_str_methods = ("endswith", "find", "index", "lstrip", "replace", |
40 |
"startswith", "strip", "rindex", "rfind", "rstrip", "__getitem__", |
41 |
"__len__", "__repr__", "__str__") |
42 |
|
43 |
-- |
44 |
gentoo-commits@l.g.o mailing list |