Skip to content

Commit

Permalink
Improve performance of expression propagation (#435)
Browse files Browse the repository at this point in the history
Making basicblock.__str__ return repr because its way cheaper
  • Loading branch information
rihi authored Aug 19, 2024
1 parent 8daf9a6 commit ecee86b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions decompiler/structures/graphs/basicblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ def __iter__(self) -> Iterator[Instruction]:
yield from self._instructions

def __str__(self) -> str:
"""Return a string representation of all instructions in the basic block."""
return "\n".join((f"{instruction}" for instruction in self))
"""Return a string representation of the block"""
# Note: Returning a string representation of all instructions here can be pretty expensive.
# Because most code does not expect this, we choose to simply return the cheap repr instead.
return repr(self)

def __repr__(self) -> str:
"""Return a debug representation of the block."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(self, address: int, ast: AbstractSyntaxTreeNode):
self.ast: AbstractSyntaxTreeNode = ast

def __str__(self) -> str:
"""Return a string representation of all instructions in the basic block."""
"""Return a string representation of the block"""
return str(self.ast)

def __repr__(self) -> str:
Expand Down
2 changes: 1 addition & 1 deletion tests/structures/graphs/test_basicblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def test_instruction_management(testblock: BasicBlock):


def test_block_representations(testblock: BasicBlock):
assert str(testblock) == "\n".join(str(instruction) for instruction in testblock)
assert str(testblock) == "BasicBlock(0x539, len=5)"
assert repr(testblock) == "BasicBlock(0x539, len=5)"


Expand Down

0 comments on commit ecee86b

Please sign in to comment.