Hoist out some work done inside a loop doing a linear scan over all