Cache source elements to optimize search.
Index:
ChangeLog
===================================================================
RCS
file: /home/tools/org.eclipse.cdt.debug.core/ChangeLog,v
retrieving revision
1.58
diff -u -r1.58 ChangeLog
--- ChangeLog 22 Nov 2002 21:29:19
-0000 1.58
+++ ChangeLog 22 Nov 2002 22:30:18 -0000
@@ -1,4 +1,8
@@
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
Index:
src/org/eclipse/cdt/debug/internal/core/sourcelookup/CProjectSourceLocation.java
===================================================================
RCS
file:
/home/tools/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CProjectSourceLocation.java,v
retrieving
revision 1.3
diff -u -r1.3 CProjectSourceLocation.java
---
src/org/eclipse/cdt/debug/internal/core/sourcelookup/CProjectSourceLocation.java 22
Nov 2002 21:29:19 -0000 1.3
+++
src/org/eclipse/cdt/debug/internal/core/sourcelookup/CProjectSourceLocation.java 22
Nov 2002 22:30:18 -0000
@@ -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;
@@ -29,6 +31,10 @@
*
The project associated with this source location
*/
private IProject fProject;
+
+ private
HashMap fCache = new HashMap( 20 );
+
+ private HashSet
fNotFoundCache = new HashSet( 20 );
/**
* Constructor for CProjectSourceLocation.
@@ -43,15 +49,24 @@
*/
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 @@
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
);
@@ -168,5 +190,31
@@
}
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();
}
}