Skip to content

Commit

Permalink
Avoid requesting getKey early: store bindings identity with
Browse files Browse the repository at this point in the history
hashcode/equals
  • Loading branch information
mickaelistria committed Aug 14, 2024
1 parent 11764b1 commit 9d6c136
Showing 1 changed file with 8 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public JavacPackageBinding getPackageBinding(PackageSymbol packageSymbol) {
return null;
}
//
private Map<String, JavacTypeBinding> typeBinding = new HashMap<>();
private Map<JavacTypeBinding, JavacTypeBinding> typeBinding = new HashMap<>();
public JavacTypeBinding getTypeBinding(JCTree tree, com.sun.tools.javac.code.Type type) {
return getTypeBinding(type, tree instanceof JCClassDecl);
}
Expand All @@ -213,29 +213,21 @@ public JavacTypeBinding getTypeBinding(com.sun.tools.javac.code.Type type, boole
&& !(errorType.getOriginalType() instanceof com.sun.tools.javac.code.Type.ForAll)
&& !(errorType.getOriginalType() instanceof com.sun.tools.javac.code.Type.ErrorType)) {
JavacTypeBinding newInstance = new JavacTypeBinding(errorType.getOriginalType(), type.tsym, isDeclaration, JavacBindingResolver.this) { };
typeBinding.putIfAbsent(newInstance.getKey(), newInstance);
JavacTypeBinding jcb = typeBinding.get(newInstance.getKey());
typeBinding.putIfAbsent(newInstance, newInstance);
JavacTypeBinding jcb = typeBinding.get(newInstance);
jcb.setRecovered(true);
return jcb;
}
JavacTypeBinding newInstance = new JavacTypeBinding(type, type.tsym, isDeclaration, JavacBindingResolver.this) { };
String k = newInstance.getKey();
if( k != null ) {
typeBinding.putIfAbsent(k, newInstance);
return typeBinding.get(k);
}
return null;
typeBinding.putIfAbsent(newInstance, newInstance);
return typeBinding.get(newInstance);
}
//
private Map<String, JavacTypeVariableBinding> typeVariableBindings = new HashMap<>();
private Map<JavacTypeVariableBinding, JavacTypeVariableBinding> typeVariableBindings = new HashMap<>();
public JavacTypeVariableBinding getTypeVariableBinding(TypeVar typeVar) {
JavacTypeVariableBinding newInstance = new JavacTypeVariableBinding(typeVar, (TypeVariableSymbol)typeVar.tsym, JavacBindingResolver.this) { };
String k = newInstance.getKey();
if( k != null ) {
typeVariableBindings.putIfAbsent(k, newInstance);
return typeVariableBindings.get(k);
}
return null;
typeVariableBindings.putIfAbsent(newInstance, newInstance);
return typeVariableBindings.get(newInstance);
}
//
private Map<String, JavacVariableBinding> variableBindings = new HashMap<>();
Expand Down

0 comments on commit 9d6c136

Please sign in to comment.