Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/bytecode/concrete.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down