cache for selectors

This commit is contained in:
Martin Mohr 2014-11-21 15:44:31 +01:00
parent 0af274a1f9
commit 0af7f105ec
1 changed files with 15 additions and 2 deletions

View File

@ -10,6 +10,9 @@
*******************************************************************************/
package com.ibm.wala.types;
import java.util.HashMap;
import java.util.Map;
import com.ibm.wala.classLoader.Language;
import com.ibm.wala.util.strings.Atom;
@ -24,8 +27,17 @@ public final class Selector {
private final Descriptor descriptor;
private final String s;
private static final Map<String,Selector> CACHE = new HashMap<String,Selector>();
public static Selector make(String selectorStr) {
return make(Language.JAVA, selectorStr);
Selector ret = CACHE.get(selectorStr);
if (ret == null) {
ret = make(Language.JAVA, selectorStr);
CACHE.put(selectorStr, ret);
}
return ret;
}
public static Selector make(Language l, String selectorStr) {
@ -44,6 +56,7 @@ public final class Selector {
public Selector(Atom name, Descriptor descriptor) {
this.name = name;
this.descriptor = descriptor;
this.s = name.toString() + descriptor.toString();
if (name == null) {
throw new IllegalArgumentException("null name");
}
@ -70,7 +83,7 @@ public final class Selector {
@Override
public String toString() {
return name.toString() + descriptor.toString();
return s;
}
public Descriptor getDescriptor() {