#372 cache length in loops