Iterating over a InsnList with an iterator traverses the list twice
When you traverse an InsnList either with a for-each loop or explicitly with an iterator:
void iter(InsnList insns) {
for(AbstractInsnNode insn : insns) { /* ... */ }
// Or
ListIterator<AbstractInsnNode> it = insns.iterator();
while(it.hasNext()) {
AbstractInsnNode insn = it.next();
/* ... */
}
}
The InsnList is traversed twice, as the call to InsnList.iterator()
calls InsnList.get(0)
internally, which populates the instruction cache by traversing the instruction list.
This is a waste of time and space if the cache is unneeded.
I'll happily submit a Merge Request unless there's a good reason that the implementation should stay as it is.