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


##########
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:
   this made me curious so I wrote a quick JMH benchmark:
   
   <details>
   
   ```java
       private static final List<?> LIST = List.of("1");
       private static final Method METHOD;
       
       static {
           Method m = null;
           try {
               m = List.class.getMethod("getFirst");
           } catch (NoSuchMethodException ex) {
               throw new IllegalStateException(ex);
           }
           METHOD = m;
       }
   
       /*
       JDK 25.0.0
       Benchmark                  Mode  Cnt    Score   Error  Units
       ReflectionJMH.reference    avgt    5    0.390 ± 0.009  ns/op
       ReflectionJMH.constMethod  avgt    5    1.098 ± 0.004  ns/op
       ReflectionJMH.getMethod    avgt    5  114.503 ± 1.479  ns/op
       */
   
       @Benchmark
       public void reference(Blackhole bh) throws ReflectiveOperationException {
           bh.consume(LIST.getFirst());
       }
   
       @Benchmark
       public void getMethod(Blackhole bh) throws ReflectiveOperationException {
           bh.consume(List.class.getMethod("getFirst").invoke(LIST));
       }
   
       @Benchmark
       public void constMethod(Blackhole bh) throws 
ReflectiveOperationException {
           bh.consume(METHOD.invoke(LIST));
       }
   ```
   </details>
   
   having it as constant makes still a big difference. Also interesting that 
the JVM couldn't completely eliminate the reflective overhead of the static 
constant based invocation.
   
   (but take this with a grain of salt, micro benchmarks are always tricky, 
method call overhead can also go down in the noise if the method is actually 
doing something non-trivial)



-- 
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