mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-03 22:35:43 +02:00
Bug 300279, add caching.
This commit is contained in:
parent
a381ee1d47
commit
77918388c1
1 changed files with 19 additions and 4 deletions
|
@ -15,6 +15,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.cdi.ICDIBreakpointHit;
|
||||
import org.eclipse.cdt.debug.core.model.ICDebugTarget;
|
||||
|
@ -43,6 +46,8 @@ public class CSourceLookupParticipant extends AbstractSourceLookupParticipant {
|
|||
|
||||
private ListenerList fListeners;
|
||||
|
||||
private Map<Object, Object[]> fCachedResults = Collections.synchronizedMap(new HashMap<Object, Object[]>());
|
||||
|
||||
/**
|
||||
* Constructor for CSourceLookupParticipant.
|
||||
*/
|
||||
|
@ -74,6 +79,11 @@ public class CSourceLookupParticipant extends AbstractSourceLookupParticipant {
|
|||
@Override
|
||||
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;
|
||||
IBreakpoint breakpoint = null;
|
||||
|
@ -84,9 +94,11 @@ public class CSourceLookupParticipant extends AbstractSourceLookupParticipant {
|
|||
if ( name == null || name.length() == 0 )
|
||||
{
|
||||
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
|
||||
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
|
||||
|
@ -129,7 +141,7 @@ public class CSourceLookupParticipant extends AbstractSourceLookupParticipant {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fCachedResults.put(object, foundElements);
|
||||
return foundElements;
|
||||
}
|
||||
|
||||
|
@ -155,6 +167,9 @@ public class CSourceLookupParticipant extends AbstractSourceLookupParticipant {
|
|||
*/
|
||||
@Override
|
||||
public void sourceContainersChanged( ISourceLookupDirector director ) {
|
||||
// clear the cache
|
||||
fCachedResults.clear();
|
||||
|
||||
Object[] listeners = fListeners.getListeners();
|
||||
for ( int i = 0; i < listeners.length; ++i )
|
||||
((ISourceLookupChangeListener)listeners[i]).sourceContainersChanged( director );
|
||||
|
|
Loading…
Add table
Reference in a new issue