changeset: 100942:f04ddbc47005
tag: tip
user: Victor Stinner
date: Tue Apr 12 18:23:59 2016 +0200
files: Lib/modulefinder.py
description:
Issue #26647: Optimize ModuleFinder.scan_opcodes_25()
Use an index rather than creating a lot of substrings.
diff -r 423e2a96189e -r f04ddbc47005 Lib/modulefinder.py
--- a/Lib/modulefinder.py Tue Apr 12 18:17:06 2016 +0200
+++ b/Lib/modulefinder.py Tue Apr 12 18:23:59 2016 +0200
@@ -338,33 +338,35 @@ class ModuleFinder:
self._add_badmodule(fullname, caller)
def scan_opcodes_25(self, co,
- unpack = struct.unpack):
+ unpack=struct.unpack):
# Scan the code, and yield 'interesting' opcode combinations
# Python 2.5 version (has absolute and relative imports)
code = co.co_code
+ index = 0
names = co.co_names
consts = co.co_consts
LOAD_LOAD_AND_IMPORT = LOAD_CONST + LOAD_CONST + IMPORT_NAME
- while code:
- c = bytes([code[0]])
+ while index < len(code):
+ c = bytes([code[index]])
if c in STORE_OPS:
- oparg, = unpack('= HAVE_ARGUMENT:
- code = code[3:]
+ index += 3
else:
- code = code[1:]
+ index += 1
def scan_code(self, co, m):
code = co.co_code