Mercurial > hg
comparison hgdemandimport/demandimportpy3.py @ 37843: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 | fcb1ecf2bef7 |
children | adb636392b3f |
comparison
equal
deleted
inserted
replaced
37840:853001c84114 | 37843:670eb4fa1b86 |
---|---|
38 """This is a LazyLoader except it also follows the _deactivated global and | 38 """This is a LazyLoader except it also follows the _deactivated global and |
39 the ignore list. | 39 the ignore list. |
40 """ | 40 """ |
41 def exec_module(self, module): | 41 def exec_module(self, module): |
42 """Make the module load lazily.""" | 42 """Make the module load lazily.""" |
43 if _deactivated or module.__name__ in ignore: | 43 if _deactivated or module.__name__ in ignores: |
44 self.loader.exec_module(module) | 44 self.loader.exec_module(module) |
45 else: | 45 else: |
46 super().exec_module(module) | 46 super().exec_module(module) |
47 | 47 |
48 # This is 3.6+ because with Python 3.5 it isn't possible to lazily load | 48 # This is 3.6+ because with Python 3.5 it isn't possible to lazily load |
60 (_extensions_loader, importlib.machinery.EXTENSION_SUFFIXES), | 60 (_extensions_loader, importlib.machinery.EXTENSION_SUFFIXES), |
61 (_source_loader, importlib.machinery.SOURCE_SUFFIXES), | 61 (_source_loader, importlib.machinery.SOURCE_SUFFIXES), |
62 (_bytecode_loader, importlib.machinery.BYTECODE_SUFFIXES), | 62 (_bytecode_loader, importlib.machinery.BYTECODE_SUFFIXES), |
63 ) | 63 ) |
64 | 64 |
65 ignore = [] | 65 ignores = set() |
66 | 66 |
67 def init(ignorelist): | 67 def init(ignoreset): |
68 global ignore | 68 global ignores |
69 ignore = ignorelist | 69 ignores = ignoreset |
70 | 70 |
71 def isenabled(): | 71 def isenabled(): |
72 return _makefinder in sys.path_hooks and not _deactivated | 72 return _makefinder in sys.path_hooks and not _deactivated |
73 | 73 |
74 def disable(): | 74 def disable(): |