1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-04 06:45:43 +02:00

Bug 300279, add caching.

This commit is contained in:
Ken Ryall 2010-02-10 21:12:26 +00:00
parent a381ee1d47
commit 77918388c1

View file

@ -15,6 +15,9 @@
package org.eclipse.cdt.debug.internal.core.sourcelookup; package org.eclipse.cdt.debug.internal.core.sourcelookup;
import java.io.File; import java.io.File;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.cdt.debug.core.cdi.ICDIBreakpointHit; import org.eclipse.cdt.debug.core.cdi.ICDIBreakpointHit;
import org.eclipse.cdt.debug.core.model.ICDebugTarget; import org.eclipse.cdt.debug.core.model.ICDebugTarget;
@ -42,6 +45,8 @@ public class CSourceLookupParticipant extends AbstractSourceLookupParticipant {
private static final NoSourceElement gfNoSource = new NoSourceElement(); private static final NoSourceElement gfNoSource = new NoSourceElement();
private ListenerList fListeners; private ListenerList fListeners;
private Map<Object, Object[]> fCachedResults = Collections.synchronizedMap(new HashMap<Object, Object[]>());
/** /**
* Constructor for CSourceLookupParticipant. * Constructor for CSourceLookupParticipant.
@ -73,7 +78,12 @@ public class CSourceLookupParticipant extends AbstractSourceLookupParticipant {
*/ */
@Override @Override
public Object[] findSourceElements( Object object ) throws CoreException { 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 // Workaround for cases when the stack frame doesn't contain the source file name
String name = null; String name = null;
IBreakpoint breakpoint = null; IBreakpoint breakpoint = null;
@ -84,9 +94,11 @@ public class CSourceLookupParticipant extends AbstractSourceLookupParticipant {
if ( name == null || name.length() == 0 ) if ( name == null || name.length() == 0 )
{ {
if (object instanceof IDebugElement) if (object instanceof IDebugElement)
return new Object[] { new CSourceNotFoundElement((IDebugElement) object, ((IDebugElement) object).getLaunch().getLaunchConfiguration(), name) }; results = new Object[] { new CSourceNotFoundElement((IDebugElement) object, ((IDebugElement) object).getLaunch().getLaunchConfiguration(), name) };
else else
return new Object[] { gfNoSource }; results = new Object[] { gfNoSource };
fCachedResults.put(object, results);
return results;
} }
} }
// See if findSourceElements(...) is the result of a Breakpoint Hit Event // See if findSourceElements(...) is the result of a Breakpoint Hit Event
@ -129,7 +141,7 @@ public class CSourceLookupParticipant extends AbstractSourceLookupParticipant {
} }
} }
} }
fCachedResults.put(object, foundElements);
return foundElements; return foundElements;
} }
@ -155,6 +167,9 @@ public class CSourceLookupParticipant extends AbstractSourceLookupParticipant {
*/ */
@Override @Override
public void sourceContainersChanged( ISourceLookupDirector director ) { public void sourceContainersChanged( ISourceLookupDirector director ) {
// clear the cache
fCachedResults.clear();
Object[] listeners = fListeners.getListeners(); Object[] listeners = fListeners.getListeners();
for ( int i = 0; i < listeners.length; ++i ) for ( int i = 0; i < listeners.length; ++i )
((ISourceLookupChangeListener)listeners[i]).sourceContainersChanged( director ); ((ISourceLookupChangeListener)listeners[i]).sourceContainersChanged( director );