RFR: jsr166 jdk9 integration wave 12

Martin Buchholz martinrb at google.com
Fri Nov 18 03:41:05 UTC 2016


On Thu, Nov 17, 2016 at 12:03 PM, Paul Sandoz <Paul.Sandoz at oracle.com>
wrote:

>
>  843         public boolean tryAdvance(Consumer<? super E> action) {
>  844             if (action == null)
>  845                 throw new NullPointerException();
>  846             int t, i;
>  847             if ((t = fence) < 0) t = getFence();
>
> Is that for optimisation purposes, since the same check is also performed
> in getFence? If so that seems like overkill
>
>
OK:

--- src/main/java/util/ArrayDeque.java 18 Nov 2016 03:22:20 -0000 1.114
+++ src/main/java/util/ArrayDeque.java 18 Nov 2016 03:38:23 -0000
@@ -866,9 +866,8 @@
         public boolean tryAdvance(Consumer<? super E> action) {
             if (action == null)
                 throw new NullPointerException();
-            int t, i;
-            if ((t = fence) < 0) t = getFence();
-            if (t == (i = cursor))
+            final int t, i;
+            if ((t = getFence()) == (i = cursor))
                 return false;
             final Object[] es = elements;
             cursor = inc(i, es.length);



>
>  848             if (t == (i = cursor))
>  849                 return false;
>  850             final Object[] es;
>  851             action.accept(nonNullElementAt(es = elements, i));
>  852             cursor = inc(i, es.length);
>


More information about the core-libs-dev mailing list