Skip to content
Open
Changes from 1 commit
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
Next Next commit
Update block indexes once after sorting instead of on every swap
BlockList.sort() registered a swap listener that called setIndex() on both
items of every quicksort swap. For items that maintain back references, such
as StringItem, each setIndex() triggers onIndexChanged() which rewrites every
reference to the item, so a single sort of a large string pool performed
O(swaps x references) work while all intermediate index values were
immediately overwritten. The updateIndex() pass that already runs after the
sort assigns each item its final index exactly once, firing onIndexChanged()
a single time per moved item, so the per-swap updates are redundant.

Sorting a resource table string pool of a large apk gets several times
faster; the resulting order and all reference values are unchanged.
  • Loading branch information
rotundtapir committed Aug 28, 2026
commit 46eead20284b13318bfb4ae6b347414715b20338
11 changes: 1 addition & 10 deletions src/main/java/com/reandroid/arsc/container/BlockList.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,7 @@ public boolean sort(Comparator<? super T> comparator) {
if (size() < 2) {
return false;
}
boolean sorted = mItems.sort(comparator, (i, j) -> {
T item1 = get(i);
T item2 = get(j);
if (item1 != null) {
item1.setIndex(i);
}
if (item2 != null) {
item2.setIndex(j);
}
});
boolean sorted = mItems.sortItems(comparator);
if (sorted) {
updateIndex();
}
Expand Down