Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import java.lang.ref.WeakReference;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicInteger;
import org.jspecify.annotations.Nullable;
Expand Down Expand Up @@ -137,11 +140,15 @@ public boolean addAll(final Collection<? extends E> collection) {
}

@Override
public boolean removeAll(final Collection<?> collection) {
public boolean removeAll(final Collection<?> c) {
if (c.isEmpty()) {
return false;
}
final Collection<?> target = c instanceof Set<?> ? c : new HashSet<>(c);
boolean changed = false;
for (final WeakReference<E> ref : backed) {
final E value = ref.get();
if (value != null && collection.contains(value)) {
for (WeakReference<E> ref : backed) {
E value = ref.get();
if (value != null && target.contains(value)) {
ref.clear();
if (backed.remove(ref)) {
liveCount.decrementAndGet();
Expand All @@ -153,11 +160,12 @@ public boolean removeAll(final Collection<?> collection) {
}

@Override
public boolean retainAll(final Collection<?> collection) {
public boolean retainAll(final Collection<?> c) {
final Collection<?> target = c.isEmpty() ? Collections.emptySet() : (c instanceof Set<?> ? c : new HashSet<>(c));
boolean changed = false;
for (final WeakReference<E> ref : backed) {
final E value = ref.get();
if (value != null && !collection.contains(value)) {
for (WeakReference<E> ref : backed) {
E value = ref.get();
if (value != null && !target.contains(value)) {
ref.clear();
if (backed.remove(ref)) {
liveCount.decrementAndGet();
Expand Down
Loading