From 9d6c13650b91c341f6b40e28bc158f677d6b54a3 Mon Sep 17 00:00:00 2001 From: Mickael Istria Date: Wed, 14 Aug 2024 10:36:31 +0200 Subject: [PATCH] Avoid requesting getKey early: store bindings identity with hashcode/equals --- .../jdt/core/dom/JavacBindingResolver.java | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacBindingResolver.java b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacBindingResolver.java index c4bd2204bb0..eaf0912d31a 100644 --- a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacBindingResolver.java +++ b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacBindingResolver.java @@ -193,7 +193,7 @@ public JavacPackageBinding getPackageBinding(PackageSymbol packageSymbol) { return null; } // - private Map typeBinding = new HashMap<>(); + private Map typeBinding = new HashMap<>(); public JavacTypeBinding getTypeBinding(JCTree tree, com.sun.tools.javac.code.Type type) { return getTypeBinding(type, tree instanceof JCClassDecl); } @@ -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 typeVariableBindings = new HashMap<>(); + private Map 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 variableBindings = new HashMap<>();