diff --git a/src/bytecode/concrete.py b/src/bytecode/concrete.py index 9826a7e0..0b1e08dd 100644 --- a/src/bytecode/concrete.py +++ b/src/bytecode/concrete.py @@ -181,6 +181,24 @@ def assemble(self) -> bytes: return bytes(b) + @classmethod + def _from_opcode( + cls: Type[T], + name: str, + opcode: int, + arg: int, + location: Optional[InstrLocation], + ) -> T: + """Fast path for from_code: arg is a raw byte (0-255), size is always 2.""" + new = object.__new__(cls) + new._name = name + new._opcode = opcode + new._arg = arg + new._location = location + new._extended_args = None + new._size = 2 + return new + @classmethod def disassemble(cls: Type[T], lineno: Optional[int], code: bytes, offset: int) -> T: index = 2 * offset @@ -353,7 +371,7 @@ def from_code( loc: Optional[InstrLocation] = ( InstrLocation._from_tuple(*pos) if pos is not None else None ) - instructions.append(ConcreteInstr(opname[op], arg, location=loc)) + instructions.append(ConcreteInstr._from_opcode(opname[op], op, arg, loc)) bytecode = ConcreteBytecode()