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
|
2002-11-22 Mikhail Khodjaiants
|
||||||
Fix in the source locator's search algorithm.
|
Fix in the source locator's search algorithm.
|
||||||
* CProjectSourceLocator.java
|
* CProjectSourceLocator.java
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
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.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation;
|
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation;
|
||||||
import org.eclipse.core.resources.IContainer;
|
import org.eclipse.core.resources.IContainer;
|
||||||
|
@ -29,6 +31,10 @@ public class CProjectSourceLocation implements ICSourceLocation
|
||||||
* The project associated with this source location
|
* The project associated with this source location
|
||||||
*/
|
*/
|
||||||
private IProject fProject;
|
private IProject fProject;
|
||||||
|
|
||||||
|
private HashMap fCache = new HashMap( 20 );
|
||||||
|
|
||||||
|
private HashSet fNotFoundCache = new HashSet( 20 );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for CProjectSourceLocation.
|
* Constructor for CProjectSourceLocation.
|
||||||
|
@ -43,15 +49,24 @@ public class CProjectSourceLocation implements ICSourceLocation
|
||||||
*/
|
*/
|
||||||
public Object findSourceElement( String name ) throws CoreException
|
public Object findSourceElement( String name ) throws CoreException
|
||||||
{
|
{
|
||||||
if ( getProject() != null )
|
Object result = null;
|
||||||
|
if ( getProject() != null && !notFoundCacheLookup( name ) )
|
||||||
{
|
{
|
||||||
File file = new File( name );
|
result = cacheLookup( name );
|
||||||
if ( file.isAbsolute() )
|
if ( result == null )
|
||||||
return findFileByAbsolutePath( name );
|
{
|
||||||
else
|
result = doFindSourceElement( name );
|
||||||
return findFileByRelativePath( getProject(), name );
|
if ( result != null )
|
||||||
|
{
|
||||||
|
cacheSourceElement( name, result );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( result == null )
|
||||||
|
{
|
||||||
|
cacheNotFound( name );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -86,6 +101,13 @@ public class CProjectSourceLocation implements ICSourceLocation
|
||||||
return fProject;
|
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 )
|
private Object findFileByAbsolutePath( String name )
|
||||||
{
|
{
|
||||||
IPath path = new Path( name );
|
IPath path = new Path( name );
|
||||||
|
@ -169,4 +191,30 @@ public class CProjectSourceLocation implements ICSourceLocation
|
||||||
|
|
||||||
return null;
|
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