From bc66f2cbf4658ec1131b13849240fa5eb2a489c5 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Mon, 8 Jan 2024 21:22:18 +0100 Subject: [PATCH] improved difficult loop in remove to help cf --- .../util/collections/ShareableValuesHashSet.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/usethesource/vallang/impl/util/collections/ShareableValuesHashSet.java b/src/main/java/io/usethesource/vallang/impl/util/collections/ShareableValuesHashSet.java index 7525a263..4161b94b 100644 --- a/src/main/java/io/usethesource/vallang/impl/util/collections/ShareableValuesHashSet.java +++ b/src/main/java/io/usethesource/vallang/impl/util/collections/ShareableValuesHashSet.java @@ -32,7 +32,7 @@ public final class ShareableValuesHashSet implements Iterable{ private int modSize; private int hashMask; - private Entry[] data; + private @Nullable Entry[] data; private int threshold; @@ -187,15 +187,16 @@ public boolean remove(Object object){ int position = hash & hashMask; Entry currentStartEntry = data[position]; - if(currentStartEntry != null){ + + if (currentStartEntry != null) { Entry entry = currentStartEntry; - do{ - if(hash == entry.hash && entry.value.equals(value)){ + do { + if (hash == entry.hash && entry.value.equals(value)) { Entry e = data[position]; data[position] = entry.next; // Reconstruct the other entries (if necessary). - while(e != entry){ + while (e != entry && e != null) { data[position] = new Entry<>(e.hash, e.value, data[position]); e = e.next; @@ -209,7 +210,7 @@ public boolean remove(Object object){ } entry = entry.next; - }while(entry != null); + } while(entry != null); } return false; @@ -338,7 +339,7 @@ private static class SetIterator implements Iterator{ private @Nullable Entry current; private int index; - public SetIterator(Entry[] entries) { + public SetIterator(@Nullable Entry[] entries) { super(); data = entries;