changeset 7032:7dfac37cfabf

dirstate: improve performance for building _dirs
author Matt Mackall <mpm@selenic.com>
date Fri, 12 Sep 2008 19:57:07 -0500
parents 19e8d034932e
children 892d27fb04a5
files mercurial/dirstate.py
diffstat 1 files changed, 14 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/dirstate.py	Fri Sep 12 15:11:02 2008 -0500
+++ b/mercurial/dirstate.py	Fri Sep 12 19:57:07 2008 -0500
@@ -16,12 +16,10 @@
 _format = ">cllll"
 
 def _finddirs(path):
-    pos = len(path)
-    while 1:
+    pos = path.rfind('/')
+    while pos != -1:
+        yield path[:pos]
         pos = path.rfind('/', 0, pos)
-        if pos == -1:
-            break
-        yield path[:pos]
 
 class dirstate(object):
 
@@ -65,10 +63,16 @@
             return self._pl
         elif name == '_dirs':
             dirs = {}
-            for f,s in self._map.items():
+            for f,s in self._map.iteritems():
                 if s[0] != 'r':
-                    for base in _finddirs(f):
-                        dirs[base] = dirs.get(base, 0) + 1
+                    pos = f.rfind('/')
+                    while pos != -1:
+                        f = f[:pos]
+                        if f in dirs:
+                            dirs[f] += 1
+                            break
+                        dirs[f] = 1
+                        pos = f.rfind('/')
             self._dirs = dirs
             return self._dirs
         elif name == '_ignore':
@@ -242,8 +246,8 @@
             for base in _finddirs(f):
                 if dirs[base] == 1:
                     del dirs[base]
-                else:
-                    dirs[base] -= 1
+                    return
+                dirs[base] -= 1
 
     def _addpath(self, f, check=False):
         oldstate = self[f]