Yet another index/enumeration replacement thread

If you are mutating the elements, indices can be a performance trap. Many collections use an Indices type which retains the collection itself (the default indices type does this), thus mutating an element while using indices will force a copy of the entire collection instead of mutating in-place.

This came up previously in the Idea: mutatingForEach for Collections thread among other places, and it is explained in the documentation for indices.

1 Like