Slow Loop

Context

Implementation

Affects

Efficiency

Problem

A slow version of a for-loop is used.

Refactorings

Enhanced For-Loop

Resolves

Efficiency

Affects

Solution

Consider the following code taken from these Efficiency tips:

static class Foo {
    int mSplat;
}
Foo[] mArray = ...

public void two() {
    int sum = 0;
    for (Foo a : mArray) {
        sum += a.mSplat;
    }
}

This is the fastest for devices without JIT and indistinguishable from one() for devices with a JIT.
But consider a hand-written counted loop for Efficiency-critical ArrayList iteration.

Links

Related