Reputation: 15038
Assuming we have an array
var foo = ["bar", "baz", "qux"]
...and we're going to re-populate that array with the same number of elements via multiple foo.append()
calls, after we've removed all elements: is there any performance advantage to keeping the existing capacity of the array?
// Keep the capacity
foo.removeAll(keepingCapacity: true)
vs.
// Don't keep the capacity
foo.removeAll(keepingCapacity: false)
Upvotes: 4
Views: 1549
Reputation: 11242
From the docs.
keepCapacity
Pass true to request that the collection avoid releasing its storage. Retaining the collection’s storage can be a useful optimization when you’re planning to grow the collection again. The default value is false.
So the answer is yes i guess.
Upvotes: 3