aboutsummaryrefslogtreecommitdiffstats
path: root/asm/src
diff options
context:
space:
mode:
authoracolyer <acolyer>2003-08-23 11:57:20 +0000
committeracolyer <acolyer>2003-08-23 11:57:20 +0000
commit31f9de4724c8c794527275aa3dccf07c0e362d77 (patch)
treed4a271527a170309d9ebc7ad967ad183eaea596b /asm/src
parent9df9062f3ee68735888de6fc92f5aafa5f2b366e (diff)
downloadaspectj-31f9de4724c8c794527275aa3dccf07c0e362d77.tar.gz
aspectj-31f9de4724c8c794527275aa3dccf07c0e362d77.zip
added a cache by handle to avoid terrible performance on larger projects
Diffstat (limited to 'asm/src')
-rw-r--r--asm/src/org/aspectj/asm/internal/AspectJElementHierarchy.java17
-rw-r--r--asm/src/org/aspectj/asm/internal/ProgramElement.java14
2 files changed, 28 insertions, 3 deletions
diff --git a/asm/src/org/aspectj/asm/internal/AspectJElementHierarchy.java b/asm/src/org/aspectj/asm/internal/AspectJElementHierarchy.java
index e8d2f9902..f33a5b9c8 100644
--- a/asm/src/org/aspectj/asm/internal/AspectJElementHierarchy.java
+++ b/asm/src/org/aspectj/asm/internal/AspectJElementHierarchy.java
@@ -17,7 +17,6 @@ import java.io.*;
import java.util.*;
import org.aspectj.asm.*;
-import org.aspectj.asm.IProgramElement.Kind;
import org.aspectj.bridge.*;
/**
@@ -29,6 +28,7 @@ public class AspectJElementHierarchy implements IHierarchy {
protected String configFile = null;
private Map fileMap = null;
+ private Map handleMap = null;
public IProgramElement getElement(String handle) {
throw new RuntimeException("unimplemented");
@@ -40,6 +40,7 @@ public class AspectJElementHierarchy implements IHierarchy {
public void setRoot(IProgramElement root) {
this.root = root;
+ handleMap = new HashMap();
}
public void addToFileMap( Object key, Object value ){
@@ -270,12 +271,20 @@ public class AspectJElementHierarchy implements IHierarchy {
// TODO: optimize this lookup
public IProgramElement findElementForHandle(String handle) {
+ // try the cache first...
+ IProgramElement ret = (IProgramElement) handleMap.get(handle);
+ if (ret != null) return ret;
+
StringTokenizer st = new StringTokenizer(handle, ProgramElement.ID_DELIM);
String file = st.nextToken();
int line = new Integer(st.nextToken()).intValue();
int col = new Integer(st.nextToken()).intValue();
// TODO: use column number when available
- return findElementForSourceLine(file, line);
+ ret = findElementForSourceLine(file, line);
+ if (ret != null) {
+ cache(handle,(ProgramElement)ret);
+ }
+ return ret;
// IProgramElement parent = findElementForType(packageName, typeName);
// if (parent == null) return null;
@@ -305,5 +314,9 @@ public class AspectJElementHierarchy implements IHierarchy {
// }
// return null;
// }
+
+ protected void cache(String handle, ProgramElement pe) {
+ handleMap.put(handle,pe);
+ }
}
diff --git a/asm/src/org/aspectj/asm/internal/ProgramElement.java b/asm/src/org/aspectj/asm/internal/ProgramElement.java
index fb89d06c3..ecf1c862d 100644
--- a/asm/src/org/aspectj/asm/internal/ProgramElement.java
+++ b/asm/src/org/aspectj/asm/internal/ProgramElement.java
@@ -88,6 +88,7 @@ public class ProgramElement implements IProgramElement {
this.formalComment = formalComment;
this.modifiers = genModifiers(modifiers);
this.accessibility = genAccessibility(modifiers);
+ cacheByHandle();
}
/**
@@ -115,6 +116,7 @@ public class ProgramElement implements IProgramElement {
this.packageName = packageName;
this.formalComment = formalComment;
this.relations = relations;
+ cacheByHandle();
}
public List getModifiers() {
@@ -395,7 +397,7 @@ public class ProgramElement implements IProgramElement {
} else {
label = parent.getName() + '.';
}
- } else if (kind == Kind.CLASS || kind == kind.ASPECT) {
+ } else if (kind == Kind.CLASS || kind == Kind.ASPECT) {
label = "";
} else {
label = parent.getName() + '.';
@@ -469,5 +471,15 @@ public class ProgramElement implements IProgramElement {
public void setDetails(String string) {
details = string;
}
+
+ /** AMC added to speed up findByHandle lookups in AspectJElementHierarchy */
+ private void cacheByHandle() {
+ String handle = getHandleIdentifier();
+ if (handle != null) {
+ AspectJElementHierarchy hierarchy = (AspectJElementHierarchy)
+ AsmManager.getDefault().getHierarchy();
+ hierarchy.cache(handle,this);
+ }
+ }
}