-
Sub-task
-
Resolution: Won't Fix
-
P3
-
8
There are several methods in Scope, mainly lookup which have two versions, the main difference between both is a parameter of type Filter<Symbol>. The version without the filter parameter just call the other one:
public Entry lookup(Name name) {
return lookup(name, noFilter);
}
public Entry lookup(Name name, Filter<Symbol> sf) {
Entry e = table[getIndex(name)];
if (e == null || e == sentinel)
return sentinel;
while (e.scope != null && (e.sym.name != name || !sf.accepts(e.sym)))
e = e.shadowed;
return e;
}
This is the definition of noFilter:
static final Filter<Symbol> noFilter = new Filter<Symbol>() {
public boolean accepts(Symbol s) {
return true;
}
};
The problem of this code is that the method: public Entry lookup(Name name), is called so many times that paying for a call to the accepts method of noFilter implies a performance slowdown.
public Entry lookup(Name name) {
return lookup(name, noFilter);
}
public Entry lookup(Name name, Filter<Symbol> sf) {
Entry e = table[getIndex(name)];
if (e == null || e == sentinel)
return sentinel;
while (e.scope != null && (e.sym.name != name || !sf.accepts(e.sym)))
e = e.shadowed;
return e;
}
This is the definition of noFilter:
static final Filter<Symbol> noFilter = new Filter<Symbol>() {
public boolean accepts(Symbol s) {
return true;
}
};
The problem of this code is that the method: public Entry lookup(Name name), is called so many times that paying for a call to the accepts method of noFilter implies a performance slowdown.