Cache results of findSourceElements for performance.
--- a/cdt/cdt_5_0_x/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLookupParticipant.java Thu Jun 18 16:49:04 2009 -0500
+++ b/cdt/cdt_5_0_x/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLookupParticipant.java Mon Jun 29 13:27:31 2009 -0500
@@ -14,6 +14,9 @@
package org.eclipse.cdt.debug.internal.core.sourcelookup;
import java.io.File;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
import org.eclipse.cdt.debug.core.model.ICStackFrame;
import org.eclipse.cdt.debug.core.sourcelookup.AbsolutePathSourceContainer;
@@ -36,6 +39,8 @@
private static final NoSourceElement gfNoSource = new NoSourceElement();
private ListenerList fListeners;
+
+ private Map<Object, Object[]> fCachedResults = Collections.synchronizedMap(new HashMap<Object, Object[]>());
/**
* Constructor for CSourceLookupParticipant.
@@ -66,6 +71,11 @@
* @see org.eclipse.debug.core.sourcelookup.AbstractSourceLookupParticipant#findSourceElements(java.lang.Object)
*/
public Object[] findSourceElements( Object object ) throws CoreException {
+ // Check the cache
+ Object[] results = fCachedResults.get(object);
+ if (results != null)
+ return results;
+
// Workaround for cases when the stack frame doesn't contain the source file name
String name = null;
if ( object instanceof IAdaptable ) {
@@ -75,9 +85,11 @@
if ( name == null || name.length() == 0 )
{
if (object instanceof IDebugElement)
- return new Object[] { new CSourceNotFoundElement( (IDebugElement) object ) };
+ results = new Object[] { new CSourceNotFoundElement( (IDebugElement) object ) };
else
- return new Object[] { gfNoSource };
+ results = new Object[] { gfNoSource };
+ fCachedResults.put(object, results);
+ return results;
}
}
}
@@ -93,6 +105,7 @@
foundElements = new Object[] { new CSourceNotFoundElement((IDebugElement) object) };
}
}
+ fCachedResults.put(object, foundElements);
return foundElements;
}