Mercurial > hg
changeset 5326:319c09685f30
dirstate: make dir collision logic faster
- shortcircuit decpath if we haven't built the _dirs map
- increment only for leafnodes of directory tree
(this should make construction more like O(nlog n) than O(n^2))
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Mon, 24 Sep 2007 12:36:38 -0500 |
parents | 5971cfc0a56a |
children | f46ab9cacd3c |
files | mercurial/dirstate.py |
diffstat | 1 files changed, 19 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/dirstate.py Mon Sep 24 12:34:26 2007 -0500 +++ b/mercurial/dirstate.py Mon Sep 24 12:36:38 2007 -0500 @@ -175,16 +175,27 @@ return self._copymap def _incpath(self, path): - for c in strutil.findall(path, '/'): - pc = path[:c] - self._dirs.setdefault(pc, 0) - self._dirs[pc] += 1 + c = path.rfind('/') + if c >= 0: + dirs = self._dirs + base = path[:c] + if base not in dirs: + self._incpath(base) + dirs[base] = 1 + else: + dirs[base] += 1 def _decpath(self, path): - for c in strutil.findall(path, '/'): - pc = path[:c] - self._dirs.setdefault(pc, 0) - self._dirs[pc] -= 1 + if "_dirs" in self.__dict__: + c = path.rfind('/') + if c >= 0: + base = path[:c] + dirs = self._dirs + if dirs[base] == 1: + del dirs[base] + self._decpath(base) + else: + dirs[base] -= 1 def _incpathcheck(self, f): if '\r' in f or '\n' in f: