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)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With