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

Comparing jsr166/src/main/java/util/ArrayList.java (file contents):
Revision 1.48 by jsr166, Thu Dec 8 05:02:32 2016 UTC vs.
Revision 1.52 by jsr166, Wed May 31 22:37:31 2017 UTC

# Line 91 | Line 91 | import java.util.function.UnaryOperator;
91   * should be used only to detect bugs.</i>
92   *
93   * <p>This class is a member of the
94 < * <a href="{@docRoot}/../technotes/guides/collections/index.html">
94 > * <a href="{@docRoot}/java/util/package-summary.html#CollectionsFramework">
95   * Java Collections Framework</a>.
96   *
97   * @param <E> the type of elements in this list
# Line 515 | Line 515 | public class ArrayList<E> extends Abstra
515       */
516      public E remove(int index) {
517          Objects.checkIndex(index, size);
518 +        final Object[] es = elementData;
519  
520 <        modCount++;
521 <        E oldValue = elementData(index);
521 <
522 <        int numMoved = size - index - 1;
523 <        if (numMoved > 0)
524 <            System.arraycopy(elementData, index+1, elementData, index,
525 <                             numMoved);
526 <        elementData[--size] = null; // clear to let GC do its work
520 >        @SuppressWarnings("unchecked") E oldValue = (E) es[index];
521 >        fastRemove(es, index);
522  
523          // checkInvariants();
524          return oldValue;
# Line 543 | Line 538 | public class ArrayList<E> extends Abstra
538       * @return {@code true} if this list contained the specified element
539       */
540      public boolean remove(Object o) {
541 <        if (o == null) {
542 <            for (int index = 0; index < size; index++)
543 <                if (elementData[index] == null) {
544 <                    fastRemove(index);
545 <                    return true;
546 <                }
547 <        } else {
548 <            for (int index = 0; index < size; index++)
549 <                if (o.equals(elementData[index])) {
550 <                    fastRemove(index);
551 <                    return true;
552 <                }
541 >        final Object[] es = elementData;
542 >        final int size = this.size;
543 >        int i = 0;
544 >        found: {
545 >            if (o == null) {
546 >                for (; i < size; i++)
547 >                    if (es[i] == null)
548 >                        break found;
549 >            } else {
550 >                for (; i < size; i++)
551 >                    if (o.equals(es[i]))
552 >                        break found;
553 >            }
554 >            return false;
555          }
556 <        return false;
556 >        fastRemove(es, i);
557 >        return true;
558      }
559  
560      /**
561       * Private remove method that skips bounds checking and does not
562       * return the value removed.
563       */
564 <    private void fastRemove(int index) {
564 >    private void fastRemove(Object[] es, int i) {
565          modCount++;
566 <        int numMoved = size - index - 1;
567 <        if (numMoved > 0)
568 <            System.arraycopy(elementData, index+1, elementData, index,
569 <                             numMoved);
572 <        elementData[--size] = null; // clear to let GC do its work
566 >        final int newSize;
567 >        if ((newSize = size - 1) > i)
568 >            System.arraycopy(es, i + 1, es, i, newSize - i);
569 >        es[size = newSize] = null;
570      }
571  
572      /**
# Line 790 | Line 787 | public class ArrayList<E> extends Abstra
787          int expectedModCount = modCount;
788          s.defaultWriteObject();
789  
790 <        // Write out size as capacity for behavioural compatibility with clone()
790 >        // Write out size as capacity for behavioral compatibility with clone()
791          s.writeInt(size);
792  
793          // Write out all elements in the proper order.
# Line 1443 | Line 1440 | public class ArrayList<E> extends Abstra
1440          private int fence; // -1 until used; then one past last index
1441          private int expectedModCount; // initialized when fence set
1442  
1443 <        /** Create new spliterator covering the given range */
1443 >        /** Creates new spliterator covering the given range. */
1444          ArrayListSpliterator(int origin, int fence, int expectedModCount) {
1445              this.index = origin;
1446              this.fence = fence;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines