Make __iter__ use list.pop() instead of pop(0), for greater efficiency.
authorZac Medico <zmedico@gentoo.org>
Tue, 2 Mar 2010 19:50:33 +0000 (19:50 -0000)
committerZac Medico <zmedico@gentoo.org>
Tue, 2 Mar 2010 19:50:33 +0000 (19:50 -0000)
(trunk r15296)

svn path=/main/branches/2.1.7/; revision=15535

pym/portage/cache/flat_hash.py

index f882c24756fc4339efb5e12acc8e71c5fa6bb841..a010e5061ba057492887b8273cf40649d5fc3303 100644 (file)
@@ -122,20 +122,19 @@ class database(fs_template.FsBased):
                """generator for walking the dir struct"""
                dirs = [(0, self.location)]
                len_base = len(self.location)
-               while len(dirs):
+               while dirs:
+                       depth, dir_path = dirs.pop()
                        try:
-                               depth = dirs[0][0]
-                               dir_list = os.listdir(dirs[0][1])
+                               dir_list = os.listdir(dir_path)
                        except OSError as e:
                                if e.errno != errno.ENOENT:
                                        raise
                                del e
-                               dirs.pop(0)
                                continue
                        for l in dir_list:
                                if l.endswith(".cpickle"):
                                        continue
-                               p = os.path.join(dirs[0][1], l)
+                               p = os.path.join(dir_path, l)
                                st = os.lstat(p)
                                if stat.S_ISDIR(st.st_mode):
                                        # Only recurse 1 deep, in order to avoid iteration over
@@ -146,4 +145,3 @@ class database(fs_template.FsBased):
                                                dirs.append((depth+1, p))
                                        continue
                                yield p[len_base+1:]
-                       dirs.pop(0)