8189845: Fix for 8157000 causes significant performance regression
authorksrini
Wed, 25 Oct 2017 21:19:38 -0700
changeset 47453 b4beec6a0a25
parent 47452 dae01bc69f86
child 47454 7a7bc84f4b6c
8189845: Fix for 8157000 causes significant performance regression Reviewed-by: jjg
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/VisibleMemberMap.java
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java	Wed Oct 25 18:12:15 2017 -0700
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java	Wed Oct 25 21:19:38 2017 -0700
@@ -895,8 +895,8 @@
             }
             VisibleMemberMap vmm = configuration.getVisibleMemberMap(te,
                     VisibleMemberMap.Kind.METHODS);
-            List<? extends Element> methods = vmm.getMembers(te);
-            for (ExecutableElement ee : ElementFilter.methodsIn(methods)) {
+            for (Element e : vmm.getMembers(te)) {
+                ExecutableElement ee = (ExecutableElement)e;
                 if (configuration.workArounds.overrides(method, ee, origin) &&
                         !isSimpleOverride(ee)) {
                     return ee;
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/VisibleMemberMap.java	Wed Oct 25 18:12:15 2017 -0700
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/VisibleMemberMap.java	Wed Oct 25 21:19:38 2017 -0700
@@ -272,9 +272,20 @@
         return result;
     }
 
+    // Cache to improve performance
+    private HashMap<ExecutableElement, Boolean> overridenMethodCache = new HashMap<>();
+
     private boolean hasOverridden(ExecutableElement method) {
+        return overridenMethodCache.computeIfAbsent(method, m -> hasOverriddenCompute(m));
+    }
+
+    private boolean hasOverriddenCompute(ExecutableElement method) {
+        if (kind != Kind.METHODS) {
+            throw new AssertionError("Unexpected kind: " + kind);
+        }
         for (TypeElement t : visibleClasses) {
-            for (ExecutableElement inheritedMethod : ElementFilter.methodsIn(classMap.get(t).members)) {
+            for (Element member : classMap.get(t).members) {
+                ExecutableElement inheritedMethod = (ExecutableElement)member;
                 if (utils.elementUtils.overrides(method, inheritedMethod, t)) {
                     return true;
                 }