Skip to content

Commit

Permalink
Optimize VisitorState#getSymbolFromName
Browse files Browse the repository at this point in the history
By delegating module lookup to `Symtab#inferModule`.
  • Loading branch information
Stephan202 committed Oct 23, 2022
1 parent 7db3f74 commit ce9da05
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 deletions check_api/src/main/java/com/google/errorprone/VisitorState.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@
import com.sun.tools.javac.code.Type.ArrayType;
import com.sun.tools.javac.code.Type.ClassType;
import com.sun.tools.javac.code.Types;
import com.sun.tools.javac.comp.Modules;
import com.sun.tools.javac.model.JavacElements;
import com.sun.tools.javac.parser.Tokens.Token;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
import com.sun.tools.javac.tree.TreeMaker;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.Convert;
import com.sun.tools.javac.util.Name;
import com.sun.tools.javac.util.Names;
import com.sun.tools.javac.util.Options;
Expand Down Expand Up @@ -406,20 +406,8 @@ public Name binaryNameFromClassname(String className) {
*/
@Nullable
public ClassSymbol getSymbolFromName(Name name) {
boolean modular = sharedState.modules.getDefaultModule() != getSymtab().noModule;
if (!modular) {
return getSymbolFromString(getSymtab().noModule, name);
}
for (ModuleSymbol msym : sharedState.modules.allModules()) {
ClassSymbol result = getSymbolFromString(msym, name);
if (result != null) {
// TODO(cushon): the path where we iterate over all modules is probably slow.
// Try to learn some lessons from JDK-8189747, and consider disallowing this case and
// requiring users to call the getSymbolFromString(ModuleSymbol, Name) overload instead.
return result;
}
}
return null;
ModuleSymbol msym = getSymtab().inferModule(Convert.packagePart(name));
return msym != null ? getSymbolFromString(msym, name) : null;
}

@Nullable
Expand Down Expand Up @@ -735,7 +723,6 @@ public static <T> Supplier<T> memoize(Supplier<T> f) {
* {@code SomeClass.instance(context)} has sizable performance improvements in aggregate.
*/
private static final class SharedState {
private final Modules modules;
private final Names names;
private final Symtab symtab;
private final ErrorProneTimings timings;
Expand All @@ -759,7 +746,6 @@ private static final class SharedState {
StatisticsCollector statisticsCollector,
Map<String, SeverityLevel> severityMap,
ErrorProneOptions errorProneOptions) {
this.modules = Modules.instance(context);
this.names = Names.instance(context);
this.symtab = Symtab.instance(context);
this.timings = ErrorProneTimings.instance(context);
Expand Down

0 comments on commit ce9da05

Please sign in to comment.