Closed chrisc36 closed 8 years ago
Good point! Would you want to contribute a fix to FastList?
The fix is pretty trivial, but sure. Would I submit a pull request?
Thanks for your suggestion and contribution!
Could you please submit a pull request to Eclipse Collections following contribution guide? We only add new changes to Eclipse Collections going forward (unless it is a bug).
Maybe there is a reason for this that I am missing, but it seems like the 'clear()' method for the List classes are very wasteful. For FastList, the .clear() method nulls the entire inner array regardless of what the size of the list is. As a result, the clear() method takes times proportional to the space allocated, not the size of the list.
This can cause severe performance degradation for some use patterns. For example, if you add one million elements to a FastList, clear that list, then add one element to the list, then clear it again, the second call to clear() will walk through and set to null the entire 1 million length internal array even though the size of the list is actually 1. Instead the clear method should only reset
size
elements of the inner array, as is done by java.util.ArrayList.This issues seems to affect primitive lists as well. For primitive ArrayLists, the clear method should just be able to set
size
to 0 since nothing needs to be GCed, instead the entire internal array is overwritten.