Bug 879299: Use idiomatic for loops, cache length