##// END OF EJS Templates
dirstate: improve performance for building _dirs
Matt Mackall -
r7032:7dfac37c default
parent child Browse files
Show More
@@ -16,12 +16,10 b' import cStringIO, osutil, sys'
16 _format = ">cllll"
16 _format = ">cllll"
17
17
18 def _finddirs(path):
18 def _finddirs(path):
19 pos = len(path)
19 pos = path.rfind('/')
20 while 1:
20 while pos != -1:
21 yield path[:pos]
21 pos = path.rfind('/', 0, pos)
22 pos = path.rfind('/', 0, pos)
22 if pos == -1:
23 break
24 yield path[:pos]
25
23
26 class dirstate(object):
24 class dirstate(object):
27
25
@@ -65,10 +63,16 b' class dirstate(object):'
65 return self._pl
63 return self._pl
66 elif name == '_dirs':
64 elif name == '_dirs':
67 dirs = {}
65 dirs = {}
68 for f,s in self._map.items():
66 for f,s in self._map.iteritems():
69 if s[0] != 'r':
67 if s[0] != 'r':
70 for base in _finddirs(f):
68 pos = f.rfind('/')
71 dirs[base] = dirs.get(base, 0) + 1
69 while pos != -1:
70 f = f[:pos]
71 if f in dirs:
72 dirs[f] += 1
73 break
74 dirs[f] = 1
75 pos = f.rfind('/')
72 self._dirs = dirs
76 self._dirs = dirs
73 return self._dirs
77 return self._dirs
74 elif name == '_ignore':
78 elif name == '_ignore':
@@ -242,8 +246,8 b' class dirstate(object):'
242 for base in _finddirs(f):
246 for base in _finddirs(f):
243 if dirs[base] == 1:
247 if dirs[base] == 1:
244 del dirs[base]
248 del dirs[base]
245 else:
249 return
246 dirs[base] -= 1
250 dirs[base] -= 1
247
251
248 def _addpath(self, f, check=False):
252 def _addpath(self, f, check=False):
249 oldstate = self[f]
253 oldstate = self[f]
General Comments 0
You need to be logged in to leave comments. Login now