Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit 6807ecf

Browse files
committed
simplify and speedup processcode
1 parent 97b4a6e commit 6807ecf

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

ethereum/vm.py

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -85,29 +85,17 @@ def __init__(self, **kwargs):
8585
# Preprocesses code, and determines which locations are in the middle
8686
# of pushdata and thus invalid
8787
def preprocess_code(code):
88-
assert isinstance(code, (str, bytes))
89-
90-
# python3 does not require ord() on byte strings
91-
if sys.version_info.major == 2:
92-
if isinstance(code, bytes):
93-
code = str(code)
94-
95-
def t_ord(char):
96-
return ord(char)
97-
else:
98-
assert isinstance(code, bytes)
99-
def t_ord(char):
100-
return char
101-
102-
i = 0
88+
assert isinstance(code, bytes)
89+
code = memoryview(code).tolist()
10390
ops = []
91+
i = 0
10492
while i < len(code):
105-
o = copy.copy(opcodes.opcodes.get(t_ord(code[i]), ['INVALID', 0, 0, 0]) + [t_ord(code[i]), 0])
93+
o = copy.copy(opcodes.opcodes.get(code[i], ['INVALID', 0, 0, 0]) + [code[i], 0])
10694
ops.append(o)
10795
if o[0][:4] == 'PUSH':
10896
for j in range(int(o[0][4:])):
10997
i += 1
110-
byte = t_ord(code[i]) if i < len(code) else 0
98+
byte = code[i] if i < len(code) else 0
11199
o[-1] = (o[-1] << 8) + byte
112100
if i < len(code):
113101
ops.append(['INVALID', 0, 0, 0, byte, 0])

0 commit comments

Comments
 (0)