Skip to content

Commit 52df5ee

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 dd6dca3 commit 52df5ee

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

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

Lines changed: 7 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,11 +222,11 @@ 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
}
229+
231230
String FWK_ADMIN_EQ = "org.eclipse.equinox.frameworkadmin.equinox"; //$NON-NLS-1$
232231
if (fVMArgs == null) {
233232
try {
@@ -261,10 +260,10 @@ public String[] getVMArguments() {
261260

262261
}
263262
if (fVMArgs == null || fVMArgs.length == 0) {
264-
hash.put(this, null);
263+
fVMArgsCache.put(this, null);
265264
return null;
266265
}
267-
hash.put(this, fVMArgs);
266+
fVMArgsCache.put(this, fVMArgs);
268267
return fVMArgs;
269268
}
270269

0 commit comments

Comments
 (0)