|
24 | 24 |
|
25 | 25 | _CASE_INSENSITIVE_PLATFORMS = 'win', 'cygwin', 'darwin' |
26 | 26 |
|
| 27 | +_unspecified = object() # ironpython: default value for dict.get |
27 | 28 |
|
28 | 29 | def _make_relax_case(): |
29 | 30 | if sys.platform.startswith(_CASE_INSENSITIVE_PLATFORMS): |
@@ -276,10 +277,10 @@ def _get_module_lock(name): |
276 | 277 |
|
277 | 278 | Should only be called with the import lock taken.""" |
278 | 279 | lock = None |
279 | | - try: |
280 | | - lock = _module_locks[name]() |
281 | | - except KeyError: |
282 | | - pass |
| 280 | + # ironpython: optimization to avoid KeyError exception |
| 281 | + lock_fn = _module_locks.get(name, _unspecified) |
| 282 | + if lock_fn is not _unspecified: |
| 283 | + lock = lock_fn() |
283 | 284 | if lock is None: |
284 | 285 | if _thread is None: |
285 | 286 | lock = _DummyModuleLock(name) |
@@ -958,10 +959,7 @@ def _spec_from_module(module, loader=None, origin=None): |
958 | 959 | location = None |
959 | 960 | if origin is None: |
960 | 961 | if location is None: |
961 | | - try: |
962 | | - origin = loader._ORIGIN |
963 | | - except AttributeError: |
964 | | - origin = None |
| 962 | + origin = getattr(loader, '_ORIGIN', None) # ironpython: optimization to avoid KeyError exception |
965 | 963 | else: |
966 | 964 | origin = location |
967 | 965 | try: |
@@ -1830,9 +1828,9 @@ def _path_importer_cache(cls, path): |
1830 | 1828 | """ |
1831 | 1829 | if path == '': |
1832 | 1830 | path = _os.getcwd() |
1833 | | - try: |
1834 | | - finder = sys.path_importer_cache[path] |
1835 | | - except KeyError: |
| 1831 | + # ironpython: optimization to avoid KeyError exception |
| 1832 | + finder = sys.path_importer_cache.get(path, _unspecified) |
| 1833 | + if finder is _unspecified: |
1836 | 1834 | finder = cls._path_hooks(path) |
1837 | 1835 | sys.path_importer_cache[path] = finder |
1838 | 1836 | return finder |
@@ -2355,6 +2353,7 @@ def _setup(sys_module, _imp_module): |
2355 | 2353 |
|
2356 | 2354 | # Directly load the os module (needed during bootstrap). |
2357 | 2355 | os_details = ('posix', ['/']), ('nt', ['\\', '/']) |
| 2356 | + if sys.platform == 'win32': os_details = reversed(os_details) # ironpython: optimization to avoid ImportError exception |
2358 | 2357 | for builtin_os, path_separators in os_details: |
2359 | 2358 | # Assumption made in _path_join() |
2360 | 2359 | assert all(len(sep) == 1 for sep in path_separators) |
|
0 commit comments