mbien commented on code in PR #4095:
URL: https://github.com/apache/netbeans/pull/4095#discussion_r869567234


##########
java/maven.indexer/src/org/netbeans/modules/maven/indexer/ClassDependencyIndexCreator.java:
##########
@@ -256,34 +256,36 @@ private static Set<String> parseField(String refereeCRC, 
String field, String re
         "org/omg/CosNaming", "org/omg/Dynamic", "org/omg/DynamicAny", 
"org/omg/IOP", "org/omg/Messaging",
         "org/omg/PortableInterceptor", "org/omg/PortableServer", 
"org/omg/SendingContext", "org/omg/stub",
         "org/w3c/dom", "org/xml/sax"
-    });
+    };
 
     /**
      * @param referrer a referring class, as {@code pkg/Outer$Inner}
-     * @param data its bytecode
+     * @param classData its bytecode
      * @param depsMap map from referring outer classes (as {@code pkg/Outer}) 
to referred-to classes (as {@code pkg/Outer$Inner})
      * @param siblings other referring classes in the same artifact (including 
this one), as {@code pkg/Outer$Inner}
      */
-    private static void addDependenciesToMap(String referrer, InputStream 
data, Map<String, Set<String>> depsMap, Set<String> siblings) throws 
IOException {
+    private static void addDependenciesToMap(String referrer, InputStream 
classData, Map<String, Set<String>> depsMap, Set<String> siblings) throws 
IOException {
+
         int shell = referrer.indexOf('$', referrer.lastIndexOf('/') + 1);
         String referrerTopLevel = shell == -1 ? referrer : 
referrer.substring(0, shell);
-        for (String referee : dependencies(data)) {
-            if (referrer.equals(referee)) {
-                continue;
-            }
-            if (siblings.contains(referee)) {
-                continue; // in same JAR, not interesting
-            }
-            if (JDK_CLASS_TEST.test(referee)) {
-                continue;
-            }
-            Set<String> referees = depsMap.get(referrerTopLevel);
-            if (referees == null) {
-                referees = new HashSet<>();
-                depsMap.put(referrerTopLevel, referees);
-            }
-            referees.add(referee);
+
+        Set<String> tmp = depsMap.get(referrerTopLevel);
+        if (tmp == null) {
+            tmp = new HashSet<>();
+            depsMap.put(referrerTopLevel, tmp);
         }
+        Set<String> referees = tmp;
+
+        dependenciesOf(classData)
+            .filter((referee) -> !referrer.equals(referee))
+            .filter((referee) -> !siblings.contains(referee)) // in same JAR, 
not interesting
+            .filter((referee) -> {
+                for (int i = 0; i < JDK_CLASS_TEST.length; i++)
+                    if (referee.startsWith(JDK_CLASS_TEST[i]))
+                        return false;

Review Comment:
   I tried two optimizations already which I didn't mention above:
   * sorted array with the most common prefixes first (setup by hand). The 
benchmark gave identical results (53s).
   * a small switch over short prefixes (java, javax, com) as pre filter before 
separate loops over arrays to create a tree structure and early elimination, 
that was actually slower since probably more difficult to optimize for the JVM 
and a longer worst case path
   
   what I didn't try yet:
   * put it into a Pattern, compile it and see what happens
   * and I also didn't do a prefix length comparison fast-path, because i 
believe this would only be very rarely a fast-path since the array has true 
prefixes, the actual paths should be longer - this might also interfere with 
JVM vectorization attempts - but i might give it a try to have data



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@netbeans.apache.org
For additional commands, e-mail: notifications-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to