Skip to content

Commit 5b9185c

Browse files
committed
Use hash-backed package caches for ClasspathJar eclipse-jdt#4933
Keep cached jar package names in a hash-backed unmodifiable set so repeated package contains() checks avoid ImmutableCollections.SetN probe costs. Fixes eclipse-jdt#4933
1 parent ddebbf2 commit 5b9185c

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJar.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.nio.file.Path;
2727
import java.nio.file.attribute.BasicFileAttributes;
2828
import java.util.Arrays;
29+
import java.util.Collections;
2930
import java.util.Date;
3031
import java.util.Enumeration;
3132
import java.util.HashSet;
@@ -89,7 +90,7 @@ private Set<String> getCachedPackageNames() {
8990
// cacheEntry.zipFile.get() != this.zipFile => update zipFile
9091
return new PackageCacheEntry(new WeakReference<>(this.zipFile), cacheEntry.lastModified , cacheEntry.fileSize, cacheEntry.packageSet);
9192
}
92-
return new PackageCacheEntry(new WeakReference<>(this.zipFile), timestamp, this.fileSize, Set.copyOf(readPackageNames()));
93+
return new PackageCacheEntry(new WeakReference<>(this.zipFile), timestamp, this.fileSize, Collections.unmodifiableSet(readPackageNames()));
9394
});
9495

9596
return entry.packageSet;
@@ -308,7 +309,7 @@ private boolean readKnownPackageNames() {
308309
this.knownPackageNames = getCachedPackageNames();
309310
return true;
310311
} catch(Exception e) {
311-
this.knownPackageNames = Set.of(); // assume for this build the zipFile is empty
312+
this.knownPackageNames = Collections.emptySet(); // assume for this build the zipFile is empty
312313
return false;
313314
}
314315
}

0 commit comments

Comments
 (0)