You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2022/03/03 16:25:39 UTC

[GitHub] [netbeans] mbien opened a new pull request #3689: project wide oprimization: improved map traversal

mbien opened a new pull request #3689:
URL: https://github.com/apache/netbeans/pull/3689


   some project wide, map/collection related optimizations (low hanging fruits).
   
    Now that `referencedIn` is fixed in NB 13, we might as well use the opportunity to improve the codebase a bit with the help of jackpot :)
   
   I picked some rules from [this](https://github.com/mbien/jackpot-inspections/) hint collection.
   
   first commit:
   If the right iterator view is used (keySet/entrySet/values), the loop body does not have to call map.get(key) on every iteration.
   ```java
   // avoid inefficient map traversal
   for ($K $k : $map.keySet()) {
       $preamble$;
       $V $v = $map.get($k);
       $body$;
   } :: $map instanceof java.util.Map && !referencedIn($k, $preamble$)
   =>
   for ($V $v : $map.values()) {
       $preamble$;
       $body$;
   }
   :: !referencedIn($k, $body$)
   =>
   for (java.util.Map.Entry<$K, $V> entry : $map.entrySet()) {
       $preamble$;
       $K $k = entry.getKey();
       $V $v = entry.getValue();
       $body$;
   }
   :: otherwise
   ;;
   ```
   
   second commit - no need to use contains() before remove()
   ```java
   // contains + remove in succession
   if ($col.contains($v)) {
       $col.remove($v);
   } :: $col instanceof java.util.Collection
   =>
   $col.remove($v);
   ;;
   
   if ($map.containsKey($k)) {
       $map.remove($k);
   } :: $map instanceof java.util.Map
   =>
   $map.remove($k);
   ;;
   ```
   
   third commit (not project wide, only two selected places to make review easier)
   This one is risky, so I only applied it selectively.
   ```java
   // contains + get in succession (dangerous! values can be null)
   if ($map.containsKey($key)) {
       $preamble$;
       $V $v = $map.get($key);
       $body$;
   } :: $map instanceof java.util.Map && !referencedIn($key, $preamble$)
   =>
   $V $v = $map.get($key);
   if ($v != null) {
       $preamble$;
       $body$;
   }
   ;;
   ```
   


-- 
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-unsubscribe@netbeans.apache.org

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



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

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


[GitHub] [netbeans] mbien merged pull request #3689: project wide oprimization: improved map traversal

Posted by GitBox <gi...@apache.org>.
mbien merged pull request #3689:
URL: https://github.com/apache/netbeans/pull/3689


   


-- 
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-unsubscribe@netbeans.apache.org

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



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

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


[GitHub] [netbeans] mbien commented on pull request #3689: project wide oprimization: improved map traversal

Posted by GitBox <gi...@apache.org>.
mbien commented on pull request #3689:
URL: https://github.com/apache/netbeans/pull/3689#issuecomment-1058887854


   thanks for the quick reviews Brad & Martin. I looked through it (again) here on gh and couldn't find any issues. 
   
   Everything is green -> lets merge it before it causes conflicts.


-- 
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-unsubscribe@netbeans.apache.org

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



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

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


[GitHub] [netbeans] mbien edited a comment on pull request #3689: project wide oprimization: improved map traversal

Posted by GitBox <gi...@apache.org>.
mbien edited a comment on pull request #3689:
URL: https://github.com/apache/netbeans/pull/3689#issuecomment-1058887854


   thanks for the quick reviews Brad & Martin. I looked through it (again) here on gh and couldn't find any issues + I did some manual testing with a fresh build.
   
   Everything is green -> going to merge it soon before it causes conflicts.


-- 
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-unsubscribe@netbeans.apache.org

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



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

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


[GitHub] [netbeans] mbien edited a comment on pull request #3689: project wide oprimization: improved map traversal

Posted by GitBox <gi...@apache.org>.
mbien edited a comment on pull request #3689:
URL: https://github.com/apache/netbeans/pull/3689#issuecomment-1058887854


   thanks for the quick reviews Brad & Martin. I looked through it (again) here on gh and couldn't find any issues. 
   
   Everything is green -> going to merge it soon before it causes conflicts.


-- 
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-unsubscribe@netbeans.apache.org

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



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

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


[GitHub] [netbeans] BradWalker commented on pull request #3689: project wide oprimization: improved map traversal

Posted by GitBox <gi...@apache.org>.
BradWalker commented on pull request #3689:
URL: https://github.com/apache/netbeans/pull/3689#issuecomment-1058762747


   Nice! And I agree, looks good to me.


-- 
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-unsubscribe@netbeans.apache.org

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



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

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