Skip to content
This repository was archived by the owner on Feb 23, 2018. It is now read-only.

Commit e7851a4

Browse files
committed
Merge pull request #9 from lrytz/findItem
Fix findItemByIndex in case of hash collisions
2 parents 6b478ad + 3218387 commit e7851a4

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/main/java/scala/tools/asm/ClassWriter.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,12 +1747,20 @@ private void put(final Item i) {
17471747
}
17481748

17491749
/**
1750-
* Find item that whose index is `index`.
1750+
* Returns the item with a specific index.
1751+
*
1752+
* @param index
1753+
* the index of the searched item.
1754+
* @return the item with the given index.
17511755
*/
17521756
public Item findItemByIndex(int index) {
1753-
int i = 0;
1754-
while (i < items.length && (items[i] == null || items[i].index != index)) i++;
1755-
return items[i];
1757+
for (Item item : items) {
1758+
while (item != null) {
1759+
if (item.index == index) return item;
1760+
item = item.next;
1761+
}
1762+
}
1763+
return null;
17561764
}
17571765

17581766
/**

0 commit comments

Comments
 (0)