Skip to content

Commit 82cff3e

Browse files
committed
perf: sets are better than lists
1 parent a66bd61 commit 82cff3e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

coverage/bytecode.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def walk(
8888
offset += 2
8989

9090

91-
TBranchTrail = tuple[list[TOffset], Optional[TArc]]
91+
TBranchTrail = tuple[set[TOffset], Optional[TArc]]
9292
TBranchTrails = dict[TOffset, list[TBranchTrail]]
9393

9494

@@ -124,10 +124,10 @@ def branch_trails(code: CodeType) -> TBranchTrails:
124124

125125
def walk_one_branch(start_at: TOffset) -> TBranchTrail:
126126
# pylint: disable=cell-var-from-loop
127-
inst_offsets: list[TOffset] = []
127+
inst_offsets: set[TOffset] = set()
128128
to_line = None
129129
for inst2 in iwalker.walk(start_at=start_at):
130-
inst_offsets.append(inst2.offset)
130+
inst_offsets.add(inst2.offset)
131131
if inst2.line_number and inst2.line_number != from_line:
132132
to_line = inst2.line_number
133133
break
@@ -139,7 +139,7 @@ def walk_one_branch(start_at: TOffset) -> TBranchTrail:
139139
if to_line is not None:
140140
return inst_offsets, (from_line, to_line)
141141
else:
142-
return [], None
142+
return set(), None
143143

144144
# Calculate two trails: one from the next instruction, and one from the
145145
# jump_target instruction.

0 commit comments

Comments
 (0)