Cache results of findSourceElements for performance.
authorryall
Mon, 29 Jun 2009 13:27:31 -0500
changeset 32 5fdb1cfe8afb
parent 31 c647861c2c67
child 33 9187acb5b384
child 35 a36bd1ef0b40
Cache results of findSourceElements for performance.
cdt/cdt_5_0_x/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLookupParticipant.java
--- 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;
 	}