Avoid making unnecessary copies of PackageSet._atoms by
authorZac Medico <zmedico@gentoo.org>
Thu, 1 Nov 2007 06:37:55 +0000 (06:37 -0000)
committerZac Medico <zmedico@gentoo.org>
Thu, 1 Nov 2007 06:37:55 +0000 (06:37 -0000)
replacing calls to self.getAtoms() with self._load().

svn path=/main/trunk/; revision=8352

pym/portage/sets/base.py
pym/portage/sets/files.py

index 8e5863cbaa8d4b82efd0bbe5051eaaa7e4b757d2..85f2e410b64a31af6f76cf7a8f01fa605fb9baf3 100644 (file)
@@ -30,9 +30,12 @@ class PackageSet(object):
                return atom in self._atoms or atom in self._nonatoms
        
        def __iter__(self):
-               for x in self.getAtoms():
+               self._load()
+               for x in self._atoms:
                        yield x
-       
+               for x in self._nonatoms:
+                       yield x
+
        def supportsOperation(self, op):
                if not op in OPERATIONS:
                        raise ValueError(op)
@@ -72,7 +75,8 @@ class PackageSet(object):
                raise NotImplementedError()
 
        def containsCPV(self, cpv):
-               for a in self.getAtoms():
+               self._load()
+               for a in self._atoms:
                        if match_from_list(a, [cpv]):
                                return True
                return False
@@ -101,7 +105,7 @@ class PackageSet(object):
                if an error occurs while parsing PROVIDE."""
                cpv_slot = "%s:%s" % (cpv, metadata["SLOT"])
                cp = dep_getkey(cpv)
-               self.getAtoms() # make sure the atoms are loaded
+               self._load() # make sure the atoms are loaded
                atoms = self._atommap.get(cp)
                if atoms:
                        best_match = best_match_to_list(cpv_slot, atoms)
@@ -125,7 +129,7 @@ class PackageSet(object):
 class EditablePackageSet(PackageSet):
 
        def update(self, atoms):
-               self.getAtoms()
+               self._load()
                modified = False
                normal_atoms = []
                for a in atoms:
@@ -149,13 +153,14 @@ class EditablePackageSet(PackageSet):
                self.write()
 
        def remove(self, atom):
-               self.getAtoms()
+               self._load()
                self._atoms.discard(atom)
                self._updateAtomMap()
                self.write()
 
        def removePackageAtoms(self, cp):
-               for a in list(self.getAtoms()):
+               self._load()
+               for a in list(self._atoms):
                        if dep_getkey(a) == cp:
                                self.remove(a)
                self.write()
index 010966c2ad0697e3d928f0b4fb9e1dec39973d22..5b6fe88380ad4472419e495872ccbd5ac8c5526d 100644 (file)
@@ -150,7 +150,8 @@ class WorldSet(StaticFileSet):
 
        def cleanPackage(self, vardb, cpv):
                self.lock()
-               worldlist = list(self.getAtoms()) # loads latest from disk
+               self._load() # loads latest from disk
+               worldlist = list(self._atoms)
                mykey = cpv_getkey(cpv)
                newworldlist = []
                for x in worldlist: