Mercurial > public > mercurial-scm > hg-stable
diff hgdemandimport/demandimportpy2.py @ 37889:670eb4fa1b86
demandimport: make module ignores a set (API)
The list of modules to ignore is used for membership testing. Yet
it is defined as a list.
Sets are more efficient for membership testing. So this commit converts
the module list to a set.
Since we took an API hit, I renamed the variable to further clarify
the change.
This appears to reduce the CPU time for running 300 invocations of
`hg log -r. -T '{rev}'` on my i7-6700K:
before: 18.64s
after: 18.44s
Differential Revision: https://phab.mercurial-scm.org/D3440
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sat, 05 May 2018 18:41:51 -0700 |
parents | 8fb5212652ec |
children | 574e1d3bc667 |
line wrap: on
line diff
--- a/hgdemandimport/demandimportpy2.py Thu Apr 19 20:33:43 2018 +0900 +++ b/hgdemandimport/demandimportpy2.py Sat May 05 18:41:51 2018 -0700 @@ -162,7 +162,7 @@ _pypy = '__pypy__' in sys.builtin_module_names def _demandimport(name, globals=None, locals=None, fromlist=None, level=-1): - if locals is None or name in ignore or fromlist == ('*',): + if locals is None or name in ignores or fromlist == ('*',): # these cases we can't really delay return _hgextimport(_origimport, name, globals, locals, fromlist, level) elif not fromlist: @@ -209,7 +209,7 @@ # while processing the import statement. return mn = '%s.%s' % (mod.__name__, attr) - if mn in ignore: + if mn in ignores: importfunc = _origimport else: importfunc = _demandmod @@ -273,11 +273,11 @@ return mod -ignore = [] +ignores = set() -def init(ignorelist): - global ignore - ignore = ignorelist +def init(ignoreset): + global ignores + ignores = ignoreset def isenabled(): return builtins.__import__ == _demandimport