8224161: Check.checkOverrideClashes n^2 algorithm
authorronsh
Thu, 13 Jun 2019 08:42:49 +0200
changeset 55358 28f4594b19c2
parent 55357 6c8d5d0e1be4
child 55374 5c4f1b7c753b
8224161: Check.checkOverrideClashes n^2 algorithm Summary: Caching type's members in Check.checkOverrideClashes to improve performance. Reviewed-by: mcimadamore, jlahoda
src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java	Thu Jun 13 08:42:47 2019 +0200
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java	Thu Jun 13 08:42:49 2019 +0200
@@ -2421,7 +2421,9 @@
 
         List<MethodSymbol> potentiallyAmbiguousList = List.nil();
         boolean overridesAny = false;
-        for (Symbol m1 : types.membersClosure(site, false).getSymbolsByName(sym.name, cf)) {
+        ArrayList<Symbol> symbolsByName = new ArrayList<>();
+        types.membersClosure(site, false).getSymbolsByName(sym.name, cf).forEach(symbolsByName::add);
+        for (Symbol m1 : symbolsByName) {
             if (!sym.overrides(m1, site.tsym, types, false)) {
                 if (m1 == sym) {
                     continue;
@@ -2439,7 +2441,7 @@
             }
 
             //...check each method m2 that is a member of 'site'
-            for (Symbol m2 : types.membersClosure(site, false).getSymbolsByName(sym.name, cf)) {
+            for (Symbol m2 : symbolsByName) {
                 if (m2 == m1) continue;
                 //if (i) the signature of 'sym' is not a subsignature of m1 (seen as
                 //a member of 'site') and (ii) m1 has the same erasure as m2, issue an error