Skip to content

Commit f602551

Browse files
committed
enhance code
1 parent ee2cdbb commit f602551

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

floss/qs/main.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -483,18 +483,18 @@ def check_is_xor(xor_key: int | None):
483483

484484

485485
class OffsetRanges:
486-
def __init__(self, offsets: Set[int]):
486+
def __init__(self, offsets: Optional[Set[int]] = None, *, _merged_ranges: Optional[List[Tuple[int, int]]] = None):
487+
if _merged_ranges is not None:
488+
self._ranges = _merged_ranges
489+
return
490+
487491
if not offsets:
488492
self._ranges: List[Tuple[int, int]] = []
489493
return
490494

491495
sorted_offsets = sorted(list(offsets))
492496

493497
ranges: List[Tuple[int, int]] = []
494-
if not sorted_offsets:
495-
self._ranges = ranges
496-
return
497-
498498
start = sorted_offsets[0]
499499
end = start
500500
for offset in sorted_offsets[1:]:
@@ -553,9 +553,8 @@ def overlaps(self, start: int, end: int) -> bool:
553553

554554
@classmethod
555555
def from_merged_ranges(cls, merged_ranges: List[Tuple[int, int]]):
556-
instance = cls.__new__(cls)
557-
instance._ranges = merged_ranges
558-
return instance
556+
return cls(_merged_ranges=merged_ranges)
557+
559558

560559
def check_is_reloc(reloc_offsets: OffsetRanges, string: ExtractedString):
561560
if reloc_offsets.overlaps(string.slice.range.offset, string.slice.range.end - 1):

tests/test_qs_pma0101.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,9 @@ def test_data_strings(pma0101_layout):
8484

8585
def test_strings(pma0101_layout):
8686
all_strings = collect_strings(pma0101_layout)
87-
import json
8887

89-
print(all_strings)
9088
assert len(all_strings) == 21
9189

92-
# Assert that there are 24 strings that are not tagged as #code or #reloc
90+
# assert count of expected strings not tagged as #code or #reloc
9391
filtered_strings = [s for s in all_strings if not s.tags.intersection({"#code", "#reloc"})]
9492
assert len(filtered_strings) == 17

0 commit comments

Comments
 (0)