From 3a791e0357d09e4e7365197ab53cbd2c58bf4311 Mon Sep 17 00:00:00 2001 From: Lars Vogel Date: Wed, 9 Sep 2026 18:46:07 +0200 Subject: [PATCH] Remove the unused enumerators from CustomHashtable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No caller ever asked the viewer hash table for its keys or its values, so both Enumeration implementations were dead. Without them the firstSlot and lastSlot fields are written but never read, and dropping those takes two branches off every insert and every rehashed entry. Assisted-by: multiple AI agents and layers of automated tooling 🤖 --- .../jface/viewers/CustomHashtable.java | 101 ------------------ 1 file changed, 101 deletions(-) diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/CustomHashtable.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/CustomHashtable.java index 4c46c28ae1f..977ead79a50 100644 --- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/CustomHashtable.java +++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/CustomHashtable.java @@ -15,9 +15,6 @@ package org.eclipse.jface.viewers; -import java.util.Enumeration; -import java.util.NoSuchElementException; - /** * CustomHashtable associates keys with values. Keys and values cannot be null. * The size of the Hashtable is the number of key/value pairs it contains. @@ -52,55 +49,6 @@ private static class HashMapEntry { } } - private static final class EmptyEnumerator implements Enumeration { - @Override - public boolean hasMoreElements() { - return false; - } - - @Override - public Object nextElement() { - throw new NoSuchElementException(); - } - } - - private class HashEnumerator implements Enumeration { - boolean key; - - int start; - - HashMapEntry entry; - - HashEnumerator(boolean isKey) { - key = isKey; - start = firstSlot; - } - - @Override - public boolean hasMoreElements() { - if (entry != null) { - return true; - } - while (start <= lastSlot) { - if (elementData[start++] != null) { - entry = elementData[start - 1]; - return true; - } - } - return false; - } - - @Override - public Object nextElement() { - if (hasMoreElements()) { - Object result = key ? entry.key : entry.value; - entry = entry.next; - return result; - } - throw new NoSuchElementException(); - } - } - transient int elementCount; transient HashMapEntry[] elementData; @@ -109,14 +57,8 @@ public Object nextElement() { private int threshold; - transient int firstSlot = 0; - - transient int lastSlot = -1; - transient private IElementComparer comparer; - private static final EmptyEnumerator emptyEnumerator = new EmptyEnumerator(); - /** * The default capacity used when not specified in the constructor. */ @@ -166,7 +108,6 @@ public CustomHashtable(int capacity, IElementComparer comparer) { if (capacity >= 0) { elementCount = 0; elementData = new HashMapEntry[capacity == 0 ? 1 : capacity]; - firstSlot = elementData.length; loadFactor = 0.75f; computeMaxSize(); } else { @@ -224,20 +165,6 @@ public boolean containsKey(Object key) { return getEntry(key) != null; } - /** - * Answers an Enumeration on the values of this Hashtable. The - * results of the Enumeration may be affected if the contents - * of this Hashtable are modified. - * - * @return an Enumeration of the values of this Hashtable - */ - public Enumeration elements() { - if (elementCount == 0) { - return emptyEnumerator; - } - return new HashEnumerator(false); - } - /** * Answers the value associated with the specified key in * this Hashtable. @@ -290,20 +217,6 @@ private boolean keyEquals(Object a, Object b) { return comparer.equals(a, b); } - /** - * Answers an Enumeration on the keys of this Hashtable. The - * results of the Enumeration may be affected if the contents - * of this Hashtable are modified. - * - * @return an Enumeration of the keys of this Hashtable - */ - public Enumeration keys() { - if (elementCount == 0) { - return emptyEnumerator; - } - return new HashEnumerator(true); - } - /** * Associate the specified value with the specified key in this Hashtable. * If the key already exists, the old value is replaced. The key and value @@ -327,12 +240,6 @@ public Object put(Object key, Object value) { rehash(); index = indexFor(hash); } - if (index < firstSlot) { - firstSlot = index; - } - if (index > lastSlot) { - lastSlot = index; - } entry = new HashMapEntry(key, value, hash); entry.next = elementData[index]; elementData[index] = entry; @@ -355,19 +262,11 @@ private void rehash() { if (length == 0) { length = 1; } - firstSlot = length; - lastSlot = -1; HashMapEntry[] newData = new HashMapEntry[length]; for (int i = elementData.length; --i >= 0;) { HashMapEntry entry = elementData[i]; while (entry != null) { int index = (entry.hash & 0x7FFFFFFF) % length; - if (index < firstSlot) { - firstSlot = index; - } - if (index > lastSlot) { - lastSlot = index; - } HashMapEntry next = entry.next; entry.next = newData[index]; newData[index] = entry;