Mercurial > hg
comparison mercurial/dirstate.py @ 6972:63d1d3e489f8
performance: normalize self._root, avoid calling os.path.join() in dirstate
In dirstate, self._join() might get called a lot. Instead of calling it
we create self._rootdir and we then only need to append the filename.
author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
---|---|
date | Tue, 02 Sep 2008 15:12:50 +0200 |
parents | b3bc518a73c3 |
children | 8c136043867b |
comparison
equal
deleted
inserted
replaced
6971:b3bc518a73c3 | 6972:63d1d3e489f8 |
---|---|
26 class dirstate(object): | 26 class dirstate(object): |
27 | 27 |
28 def __init__(self, opener, ui, root): | 28 def __init__(self, opener, ui, root): |
29 self._opener = opener | 29 self._opener = opener |
30 self._root = root | 30 self._root = root |
31 self._rootdir = os.path.join(root, '') | |
31 self._dirty = False | 32 self._dirty = False |
32 self._dirtypl = False | 33 self._dirtypl = False |
33 self._ui = ui | 34 self._ui = ui |
34 | 35 |
35 def __getattr__(self, name): | 36 def __getattr__(self, name): |
97 return self.normalize | 98 return self.normalize |
98 else: | 99 else: |
99 raise AttributeError, name | 100 raise AttributeError, name |
100 | 101 |
101 def _join(self, f): | 102 def _join(self, f): |
102 return os.path.join(self._root, f) | 103 # much faster than os.path.join() |
104 return self._rootdir + f | |
103 | 105 |
104 def flagfunc(self, fallback): | 106 def flagfunc(self, fallback): |
105 if self._checklink: | 107 if self._checklink: |
106 if self._checkexec: | 108 if self._checkexec: |
107 def f(x): | 109 def f(x): |
108 p = os.path.join(self._root, x) | 110 p = self._join(x) |
109 if os.path.islink(p): | 111 if os.path.islink(p): |
110 return 'l' | 112 return 'l' |
111 if util.is_exec(p): | 113 if util.is_exec(p): |
112 return 'x' | 114 return 'x' |
113 return '' | 115 return '' |
114 return f | 116 return f |
115 def f(x): | 117 def f(x): |
116 if os.path.islink(os.path.join(self._root, x)): | 118 if os.path.islink(self._join(x)): |
117 return 'l' | 119 return 'l' |
118 if 'x' in fallback(x): | 120 if 'x' in fallback(x): |
119 return 'x' | 121 return 'x' |
120 return '' | 122 return '' |
121 return f | 123 return f |
122 if self._checkexec: | 124 if self._checkexec: |
123 def f(x): | 125 def f(x): |
124 if 'l' in fallback(x): | 126 if 'l' in fallback(x): |
125 return 'l' | 127 return 'l' |
126 if util.is_exec(os.path.join(self._root, x)): | 128 if util.is_exec(self._join(x)): |
127 return 'x' | 129 return 'x' |
128 return '' | 130 return '' |
129 return f | 131 return f |
130 return fallback | 132 return fallback |
131 | 133 |