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


##########
extide/gradle/netbeans-gradle-tooling/src/main/java/org/netbeans/modules/gradle/tooling/NbProjectInfoBuilder.java:
##########
@@ -1362,18 +1370,24 @@ private void detectArtifacts(NbProjectInfoModel model) {
             }
         }
         Map<String, Object> archives = new HashMap<>();
-        beforeGradle("5.2", () -> {
-            // The jar.getCassifier() and jar.getArchievePath() are deprecated 
since 5.2
-            // These methods got removed in 8.0
-            project.getTasks().withType(Jar.class).forEach(jar -> {
-                archives.put(jar.getClassifier(), jar.getArchivePath());
-            });
-        });
-        sinceGradle("5.2", () -> {
-            project.getTasks().withType(Jar.class).forEach(jar -> {
-                archives.put(jar.getArchiveClassifier().get(), 
jar.getDestinationDirectory().file(jar.getArchiveFileName().get()).get().getAsFile());
-            });
-        });
+        Consumer<Jar> jarToArchivesClassifierAndPath =
+            sinceGradleOrDefault(
+                "5.2",
+                () -> jar -> archives.put(jar.getArchiveClassifier().get(), 
jar.getDestinationDirectory().file(jar.getArchiveFileName().get()).get().getAsFile()),
+                () -> {
+                    // The jar.getCassifier() and jar.getArchievePath() are 
deprecated since 5.2
+                    // These methods got removed in 8.0
+                    Method getClassifier = 
Jar.class.getMethod("getClassifier");

Review Comment:
   @wrprice interesting, will take a closer look tomorrow at your results. Btw, 
after I posted that, I also added `MethodHandle` to the benchmark and it was 
indistinguishable from a regular method call. It appears JVM is able to 
eliminate the indirection completely in that case (which is what I hoped it 
would, but at the same time this looks almost too good to be true).
   
   ```
       JDK 25.0.0
       Benchmark                  Mode  Cnt    Score   Error  Units
       ReflectionJMH.reference    avgt    5    0.388 ± 0.005  ns/op
       ReflectionJMH.constHandle  avgt    5    0.389 ± 0.006  ns/op
       ReflectionJMH.constMethod  avgt    5    1.101 ± 0.011  ns/op
       ReflectionJMH.getMethod    avgt    5  114.660 ± 3.117  ns/op
   ```
   
   ```java
   ...
           MethodHandle mh;
           try {
               mh = MethodHandles.publicLookup().unreflect(METHOD);
           } catch (ReflectiveOperationException ex) {
               throw new IllegalStateException(ex);
           }
           METHOD_HANDLE = mh;
   ```
   
   ```java
   ...
       @Benchmark
       public void constHandle(Blackhole bh) throws Throwable {
           bh.consume(METHOD_HANDLE.invokeExact(LIST));
       }
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

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

Reply via email to