ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/PriorityQueue.java
(Generate patch)

Comparing jsr166/src/main/java/util/PriorityQueue.java (file contents):
Revision 1.114 by jsr166, Wed Nov 30 18:12:52 2016 UTC vs.
Revision 1.115 by jsr166, Fri Dec 2 07:11:36 2016 UTC

# Line 823 | Line 823 | public class PriorityQueue<E> extends Ab
823      }
824  
825      final class PriorityQueueSpliterator implements Spliterator<E> {
826        /*
827         * This is very similar to ArrayList Spliterator, except for
828         * extra null checks.
829         */
826          private int index;            // current index, modified on advance/split
827          private int fence;            // -1 until first use
828          private int expectedModCount; // initialized when fence set
# Line 855 | Line 851 | public class PriorityQueue<E> extends Ab
851  
852          @SuppressWarnings("unchecked")
853          public void forEachRemaining(Consumer<? super E> action) {
858            int i, hi, mc; // hoist accesses and checks from loop
859            final Object[] a;
854              if (action == null)
855                  throw new NullPointerException();
856 <            if ((a = queue) != null) {
857 <                if ((hi = fence) < 0) {
858 <                    mc = modCount;
859 <                    hi = size;
860 <                }
861 <                else
862 <                    mc = expectedModCount;
869 <                if ((i = index) >= 0 && (index = hi) <= a.length) {
870 <                    for (E e;; ++i) {
871 <                        if (i < hi) {
872 <                            if ((e = (E) a[i]) == null) // must be CME
873 <                                break;
874 <                            action.accept(e);
875 <                        }
876 <                        else if (modCount != mc)
877 <                            break;
878 <                        else
879 <                            return;
880 <                    }
881 <                }
856 >            if (fence < 0) { fence = size; expectedModCount = modCount; }
857 >            final Object[] a = queue;
858 >            int i, hi; E e;
859 >            for (i = index, index = hi = fence; i < hi; i++) {
860 >                if ((e = (E) a[i]) == null)
861 >                    break;      // must be CME
862 >                action.accept(e);
863              }
864 <            throw new ConcurrentModificationException();
864 >            if (modCount != expectedModCount)
865 >                throw new ConcurrentModificationException();
866          }
867  
868 +        @SuppressWarnings("unchecked")
869          public boolean tryAdvance(Consumer<? super E> action) {
870              if (action == null)
871                  throw new NullPointerException();
872 <            int hi = getFence(), lo = index;
873 <            if (lo >= 0 && lo < hi) {
874 <                index = lo + 1;
875 <                @SuppressWarnings("unchecked") E e = (E)queue[lo];
876 <                if (e == null)
872 >            if (fence < 0) { fence = size; expectedModCount = modCount; }
873 >            int i;
874 >            if ((i = index) < fence) {
875 >                index = i + 1;
876 >                E e;
877 >                if ((e = (E) queue[i]) == null
878 >                    || modCount != expectedModCount)
879                      throw new ConcurrentModificationException();
880                  action.accept(e);
896                if (modCount != expectedModCount)
897                    throw new ConcurrentModificationException();
881                  return true;
882              }
883              return false;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines