Skip to content

Commit 2ecbcf2

Browse files
vogellaclaude
andcommitted
Speed-up VM arguments lookup in AbstractBundleContainer
Optimized the getVMArguments() method by replacing an inefficient O(n) iteration through all cache entries with a direct O(1) HashMap lookup. Also renamed the cache field from 'hash' to 'fVMArgsCache' for clarity. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent ca484e5 commit 2ecbcf2

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/AbstractBundleContainer.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import java.io.File;
1818
import java.io.IOException;
1919
import java.util.HashMap;
20-
import java.util.Map.Entry;
2120

2221
import org.eclipse.core.runtime.CoreException;
2322
import org.eclipse.core.runtime.IProgressMonitor;
@@ -66,7 +65,7 @@ public abstract class AbstractBundleContainer extends PlatformObject implements
6665
*/
6766
private String[] fVMArgs;
6867

69-
static private HashMap<AbstractBundleContainer, String[]> hash = new HashMap<>();
68+
private static final HashMap<AbstractBundleContainer, String[]> fVMArgsCache = new HashMap<>();
7069

7170
/**
7271
* Resolves any string substitution variables in the given text returning
@@ -223,10 +222,9 @@ protected void clearResolutionStatus() {
223222

224223
@Override
225224
public String[] getVMArguments() {
226-
for (Entry<AbstractBundleContainer, String[]> entry : hash.entrySet()) {
227-
if (entry.getKey().equals(this)) {
228-
return entry.getValue();
229-
}
225+
String[] cachedArgs = fVMArgsCache.get(this);
226+
if (cachedArgs != null) {
227+
return cachedArgs;
230228
}
231229
String FWK_ADMIN_EQ = "org.eclipse.equinox.frameworkadmin.equinox"; //$NON-NLS-1$
232230
if (fVMArgs == null) {
@@ -261,10 +259,10 @@ public String[] getVMArguments() {
261259

262260
}
263261
if (fVMArgs == null || fVMArgs.length == 0) {
264-
hash.put(this, null);
262+
fVMArgsCache.put(this, null);
265263
return null;
266264
}
267-
hash.put(this, fVMArgs);
265+
fVMArgsCache.put(this, fVMArgs);
268266
return fVMArgs;
269267
}
270268

0 commit comments

Comments
 (0)