mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Cache source elements to optimize search.
This commit is contained in:
parent
d2726b6f54
commit
0a4fdc5cd3
2 changed files with 59 additions and 7 deletions
|
@ -1,3 +1,7 @@
|
|||
2002-11-22 Mikhail Khodjaiants
|
||||
Cache source elements to optimize search.
|
||||
* CProjectSourceLocator.java
|
||||
|
||||
2002-11-22 Mikhail Khodjaiants
|
||||
Fix in the source locator's search algorithm.
|
||||
* CProjectSourceLocator.java
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
package org.eclipse.cdt.debug.internal.core.sourcelookup;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation;
|
||||
import org.eclipse.core.resources.IContainer;
|
||||
|
@ -30,6 +32,10 @@ public class CProjectSourceLocation implements ICSourceLocation
|
|||
*/
|
||||
private IProject fProject;
|
||||
|
||||
private HashMap fCache = new HashMap( 20 );
|
||||
|
||||
private HashSet fNotFoundCache = new HashSet( 20 );
|
||||
|
||||
/**
|
||||
* Constructor for CProjectSourceLocation.
|
||||
*/
|
||||
|
@ -43,15 +49,24 @@ public class CProjectSourceLocation implements ICSourceLocation
|
|||
*/
|
||||
public Object findSourceElement( String name ) throws CoreException
|
||||
{
|
||||
if ( getProject() != null )
|
||||
Object result = null;
|
||||
if ( getProject() != null && !notFoundCacheLookup( name ) )
|
||||
{
|
||||
File file = new File( name );
|
||||
if ( file.isAbsolute() )
|
||||
return findFileByAbsolutePath( name );
|
||||
else
|
||||
return findFileByRelativePath( getProject(), name );
|
||||
result = cacheLookup( name );
|
||||
if ( result == null )
|
||||
{
|
||||
result = doFindSourceElement( name );
|
||||
if ( result != null )
|
||||
{
|
||||
cacheSourceElement( name, result );
|
||||
}
|
||||
}
|
||||
if ( result == null )
|
||||
{
|
||||
cacheNotFound( name );
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return result;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -86,6 +101,13 @@ public class CProjectSourceLocation implements ICSourceLocation
|
|||
return fProject;
|
||||
}
|
||||
|
||||
private Object doFindSourceElement( String name )
|
||||
{
|
||||
File file = new File( name );
|
||||
return ( file.isAbsolute() ) ? findFileByAbsolutePath( name ) :
|
||||
findFileByRelativePath( getProject(), name );
|
||||
}
|
||||
|
||||
private Object findFileByAbsolutePath( String name )
|
||||
{
|
||||
IPath path = new Path( name );
|
||||
|
@ -169,4 +191,30 @@ public class CProjectSourceLocation implements ICSourceLocation
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Object cacheLookup( String name )
|
||||
{
|
||||
return fCache.get( name );
|
||||
}
|
||||
|
||||
private boolean notFoundCacheLookup( String name )
|
||||
{
|
||||
return fNotFoundCache.contains( name );
|
||||
}
|
||||
|
||||
private void cacheSourceElement( String name, Object element )
|
||||
{
|
||||
fCache.put( name, element );
|
||||
}
|
||||
|
||||
private void cacheNotFound( String name )
|
||||
{
|
||||
fNotFoundCache.add( name );
|
||||
}
|
||||
|
||||
protected void dispose()
|
||||
{
|
||||
fCache.clear();
|
||||
fNotFoundCache.clear();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue