eclipse-collections
eclipse-collections copied to clipboard
Is it necessary to wipe in removeIf?
In the removeIf of primitive types, the template zeroes the remaining of the list. Is it really necessary to do so?
@Override
public boolean removeIf(<name>Predicate predicate)
{
int currentFilledIndex = 0;
for (int i = 0; i \< this.size; i++)
{
<type> item = this.items[i];
if (!predicate.accept(item))
{
// keep it
if (currentFilledIndex != i)
{
this.items[currentFilledIndex] = item;
}
currentFilledIndex++;
}
}
boolean changed = currentFilledIndex \< this.size;
this.wipeAndResetTheEnd(currentFilledIndex);
return changed;
}
private void wipeAndResetTheEnd(int newCurrentFilledIndex)
{
for (int i = newCurrentFilledIndex; i \< this.size; i++)
{
this.items[i] = <zero.(type)>;
}
this.size = newCurrentFilledIndex;
}