You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by ne...@apache.org on 2022/08/15 17:03:56 UTC

[netbeans] branch delivery updated: org.netbeans.modules.java.hints.bugs.Unused doesn't cancel properly

This is an automated email from the ASF dual-hosted git repository.

neilcsmith pushed a commit to branch delivery
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/delivery by this push:
     new 74861d063b org.netbeans.modules.java.hints.bugs.Unused doesn't cancel properly
     new a8d131829e Merge pull request #4501 from mbien/cancel-unused-hint
74861d063b is described below

commit 74861d063b547e16d94f19171181a6fb1fc318db
Author: Michael Bien <mb...@gmail.com>
AuthorDate: Sat Aug 13 03:29:04 2022 +0200

    org.netbeans.modules.java.hints.bugs.Unused doesn't cancel properly
    
     - streams are not very good at canceling
     - by using a plain loop we can simply break out of it
     - further: convertUnused is the slow part, not findUnused, and it isn't
       cancelable
    
    issue:
    
     - a synthetic file with 10k fields pins a thread for about 20s
       at 100%
     - most editor features don't work during that time, e.g completion
---
 .../org/netbeans/modules/java/hints/bugs/Unused.java   | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/java/java.hints/src/org/netbeans/modules/java/hints/bugs/Unused.java b/java/java.hints/src/org/netbeans/modules/java/hints/bugs/Unused.java
index 7cb214e5cc..23ac810033 100644
--- a/java/java.hints/src/org/netbeans/modules/java/hints/bugs/Unused.java
+++ b/java/java.hints/src/org/netbeans/modules/java/hints/bugs/Unused.java
@@ -19,6 +19,7 @@
 package org.netbeans.modules.java.hints.bugs;
 
 import com.sun.source.tree.Tree.Kind;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.stream.Collectors;
 import javax.lang.model.element.ElementKind;
@@ -46,11 +47,18 @@ public class Unused {
 
     @TriggerTreeKind(Kind.COMPILATION_UNIT)
     public static List<ErrorDescription> unused(HintContext ctx) {
-         return UnusedDetector.findUnused(ctx.getInfo(), () -> ctx.isCanceled())
-                             .stream()
-                             .map(ud -> convertUnused(ctx, ud))
-                             .filter(err -> err != null)
-                             .collect(Collectors.toList());
+        List<UnusedDescription> unused = UnusedDetector.findUnused(ctx.getInfo(), () -> ctx.isCanceled());
+        List<ErrorDescription> result = new ArrayList<>(unused.size());
+        for (UnusedDescription ud : unused) {
+            if (ctx.isCanceled()) {
+                break;
+            }
+            ErrorDescription err = convertUnused(ctx, ud);
+            if (err != null) {
+                result.add(err);
+            }
+        }
+        return result;
     }
 
     @Messages({


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org

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