Skip to content

Commit 0626c0e

Browse files
Merge branch 'main' into perf/type-check-on-insertion
2 parents 9244884 + b67adbf commit 0626c0e

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

src/bytecode/concrete.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,24 @@ def assemble(self) -> bytes:
181181

182182
return bytes(b)
183183

184+
@classmethod
185+
def _from_opcode(
186+
cls: Type[T],
187+
name: str,
188+
opcode: int,
189+
arg: int,
190+
location: Optional[InstrLocation],
191+
) -> T:
192+
"""Fast path for from_code: arg is a raw byte (0-255), size is always 2."""
193+
new = object.__new__(cls)
194+
new._name = name
195+
new._opcode = opcode
196+
new._arg = arg
197+
new._location = location
198+
new._extended_args = None
199+
new._size = 2
200+
return new
201+
184202
@classmethod
185203
def disassemble(cls: Type[T], lineno: Optional[int], code: bytes, offset: int) -> T:
186204
index = 2 * offset
@@ -353,7 +371,7 @@ def from_code(
353371
loc: Optional[InstrLocation] = (
354372
InstrLocation._from_tuple(*pos) if pos is not None else None
355373
)
356-
instructions.append(ConcreteInstr(opname[op], arg, location=loc))
374+
instructions.append(ConcreteInstr._from_opcode(opname[op], op, arg, loc))
357375

358376
bytecode = ConcreteBytecode()
359377

0 commit comments

Comments
 (0)