comparison mercurial/match.py @ 25188:2773540c3650

match: remove unnecessary optimization where visitdir() returns 'all' Match's visitdir() was prematurely optimized to return 'all' in some cases, so that the caller would not have to call it for directories within the current directory. This change makes the visitdir system less flexible for future changes, such as making visitdir consider the match's include and exclude patterns. As a demonstration of this optimization not actually improving performance, I ran 'hg files -r . media' on the Mozilla repository, stored as treemanifest revlogs. With best of ten tries, the command took 1.07s both with and without the optimization, even though the optimization reduced the calls from visitdir() from 987 to 51.
author Drew Gottlieb <drgott@google.com>
date Wed, 06 May 2015 15:59:35 -0700
parents 6f7048cc2419
children 1c8c33eaea0a
comparison
equal deleted inserted replaced
25187:670c1df688fd 25188:2773540c3650
172 @propertycache 172 @propertycache
173 def _dirs(self): 173 def _dirs(self):
174 return set(util.dirs(self._fmap)) | set(['.']) 174 return set(util.dirs(self._fmap)) | set(['.'])
175 175
176 def visitdir(self, dir): 176 def visitdir(self, dir):
177 '''Helps while traversing a directory tree. Returns the string 'all' if 177 return (not self._fmap or '.' in self._fmap or
178 the given directory and all subdirectories should be visited. Otherwise 178 dir in self._fmap or dir in self._dirs or
179 returns True or False indicating whether the given directory should be 179 any(parentdir in self._fmap
180 visited. If 'all' is returned, calling this method on a subdirectory 180 for parentdir in util.finddirs(dir)))
181 gives an undefined result.'''
182 if not self._fmap or self.exact(dir):
183 return 'all'
184 return dir in self._dirs
185 181
186 def exact(self, f): 182 def exact(self, f):
187 '''Returns True if f is in .files().''' 183 '''Returns True if f is in .files().'''
188 return f in self._fmap 184 return f in self._fmap
189 185