Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
asm
asm
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3
    • Issues 3
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge Requests 3
    • Merge Requests 3
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • CI / CD
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • asm
  • asmasm
  • Issues
  • #317910

Closed
Open
Opened Jun 15, 2020 by Oskar Haarklou Veileborg@oskar

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.

Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: asm/asm#317910