Replace the use of an accumulator list with a listBuffer. The advantage is that the last step to turn the acc listbuffer into a list can be done without allocating any objects, unlike the reverse which needs to do those allocations.
Note that this type of local use of mutable data structures, whose mutability does not scope the scope of a function body, is common in all the Scala codebase.
Replace the use of an accumulator list with a listBuffer. The advantage is that the last step to turn the
acc
listbuffer into a list can be done without allocating any objects, unlike the reverse which needs to do those allocations.Note that this type of local use of mutable data structures, whose mutability does not scope the scope of a function body, is common in all the Scala codebase.