--- jsr166/src/main/java/util/ArrayList.java 2016/11/16 00:17:25 1.44 +++ jsr166/src/main/java/util/ArrayList.java 2016/11/30 03:31:47 1.45 @@ -1291,9 +1291,8 @@ public class ArrayList extends Abstra public Spliterator spliterator() { checkForComodification(); - // ArrayListSpliterator is not used because late-binding logic - // is different here - return new Spliterator<>() { + // ArrayListSpliterator not used here due to late-binding + return new Spliterator() { private int index = offset; // current index, modified on advance/split private int fence = -1; // -1 until used; then one past last index private int expectedModCount; // initialized when fence set @@ -1307,12 +1306,11 @@ public class ArrayList extends Abstra return hi; } - public ArrayListSpliterator trySplit() { + public ArrayList.ArrayListSpliterator trySplit() { int hi = getFence(), lo = index, mid = (lo + hi) >>> 1; - // ArrayListSpliterator could be used here as the source is already bound + // ArrayListSpliterator can be used here as the source is already bound return (lo >= mid) ? null : // divide range in half unless too small - new ArrayListSpliterator<>(root, lo, index = mid, - expectedModCount); + root.new ArrayListSpliterator(lo, index = mid, expectedModCount); } public boolean tryAdvance(Consumer action) { @@ -1354,7 +1352,7 @@ public class ArrayList extends Abstra } public long estimateSize() { - return (long) (getFence() - index); + return getFence() - index; } public int characteristics() { @@ -1391,11 +1389,11 @@ public class ArrayList extends Abstra */ @Override public Spliterator spliterator() { - return new ArrayListSpliterator<>(this, 0, -1, 0); + return new ArrayListSpliterator(0, -1, 0); } /** Index-based split-by-two, lazily initialized Spliterator */ - static final class ArrayListSpliterator implements Spliterator { + final class ArrayListSpliterator implements Spliterator { /* * If ArrayLists were immutable, or structurally immutable (no @@ -1429,15 +1427,12 @@ public class ArrayList extends Abstra * these streamlinings. */ - private final ArrayList list; private int index; // current index, modified on advance/split private int fence; // -1 until used; then one past last index private int expectedModCount; // initialized when fence set /** Create new spliterator covering the given range */ - ArrayListSpliterator(ArrayList list, int origin, int fence, - int expectedModCount) { - this.list = list; // OK if null unless traversed + ArrayListSpliterator(int origin, int fence, int expectedModCount) { this.index = origin; this.fence = fence; this.expectedModCount = expectedModCount; @@ -1445,23 +1440,17 @@ public class ArrayList extends Abstra private int getFence() { // initialize fence to size on first use int hi; // (a specialized variant appears in method forEach) - ArrayList lst; if ((hi = fence) < 0) { - if ((lst = list) == null) - hi = fence = 0; - else { - expectedModCount = lst.modCount; - hi = fence = lst.size; - } + expectedModCount = modCount; + hi = fence = size; } return hi; } - public ArrayListSpliterator trySplit() { + public ArrayListSpliterator trySplit() { int hi = getFence(), lo = index, mid = (lo + hi) >>> 1; return (lo >= mid) ? null : // divide range in half unless too small - new ArrayListSpliterator<>(list, lo, index = mid, - expectedModCount); + new ArrayListSpliterator(lo, index = mid, expectedModCount); } public boolean tryAdvance(Consumer action) { @@ -1470,9 +1459,9 @@ public class ArrayList extends Abstra int hi = getFence(), i = index; if (i < hi) { index = i + 1; - @SuppressWarnings("unchecked") E e = (E)list.elementData[i]; + @SuppressWarnings("unchecked") E e = (E)elementData[i]; action.accept(e); - if (list.modCount != expectedModCount) + if (modCount != expectedModCount) throw new ConcurrentModificationException(); return true; } @@ -1481,13 +1470,13 @@ public class ArrayList extends Abstra public void forEachRemaining(Consumer action) { int i, hi, mc; // hoist accesses and checks from loop - ArrayList lst; Object[] a; + Object[] a; if (action == null) throw new NullPointerException(); - if ((lst = list) != null && (a = lst.elementData) != null) { + if ((a = elementData) != null) { if ((hi = fence) < 0) { - mc = lst.modCount; - hi = lst.size; + mc = modCount; + hi = size; } else mc = expectedModCount; @@ -1496,7 +1485,7 @@ public class ArrayList extends Abstra @SuppressWarnings("unchecked") E e = (E) a[i]; action.accept(e); } - if (lst.modCount == mc) + if (modCount == mc) return; } } @@ -1504,7 +1493,7 @@ public class ArrayList extends Abstra } public long estimateSize() { - return (long) (getFence() - index); + return getFence() - index; } public int characteristics() {