-
Notifications
You must be signed in to change notification settings - Fork 614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add method wrapCopy to Primitive Lists to mirror the functionality in FastList #742
Comments
Eclipse collections is used by applications that are very sensitive to garbage. Adding extra copies is not necessary most of the time and therefore we leave that to the application. The behavior is documented on the actual
|
We can add a method named |
…tList. Fixes eclipse#742. Signed-off-by: Donald Raab <Donald.Raab@bnymellon.com>
…tList. Fixes eclipse#742. Signed-off-by: Donald Raab <Donald.Raab@bnymellon.com>
…tList. Fixes eclipse#742. Signed-off-by: Donald Raab <Donald.Raab@bnymellon.com>
…tList. Fixes eclipse#742. Signed-off-by: Donald Raab <Donald.Raab@bnymellon.com>
…tList. Fixes eclipse#742. Signed-off-by: Donald Raab <Donald.Raab@bnymellon.com>
…tList. Fixes eclipse#742. Signed-off-by: Donald Raab <Donald.Raab@bnymellon.com>
Let me take
MutableIntList
as an example.int[] array = { 1, 2, 3, 4 };
MutableIntList list = IntLists.mutable.of(array);
In the source code of
IntArrayList
, the constructor takes an initial array as parameter and holds the reference to it inthis.items
:public IntArrayList(int... array)
{
this.size = array.length;
this.items = array;
}
When invoke
removeAtIndex()
, the item will be removed from both the list and the initial array (this behavior is a disaster and should be documented clearly!):list.removeAtIndex(0);
System.out.println(Arrays.toString(array)); // [2,3,4,0]
On the other hand, if invoke
add()
beforeremoveAtIndex()
, due toensureCapacityForAdd()
,this.items
will reference to a new larger array, andremoveAtIndex()
will no longer affect the initial array:list.add(5);
list.removeAtIndex(0);
System.out.println(Arrays.toString(array)); // [1,2,3,4]
So for Mutable Primitive List, pls consider
removeAtIndex()
which affects on the list onlyThe text was updated successfully, but these errors were encountered: