< prev index next >

src/java.base/share/classes/java/util/ArrayList.java

Print this page
rev 15716 : 8166840: Synthetic bridge constructor in ArrayList$Itr blocks inlining
Reviewed-by: vlivanov, mhaupt


 859 
 860     /**
 861      * Returns an iterator over the elements in this list in proper sequence.
 862      *
 863      * <p>The returned iterator is <a href="#fail-fast"><i>fail-fast</i></a>.
 864      *
 865      * @return an iterator over the elements in this list in proper sequence
 866      */
 867     public Iterator<E> iterator() {
 868         return new Itr();
 869     }
 870 
 871     /**
 872      * An optimized version of AbstractList.Itr
 873      */
 874     private class Itr implements Iterator<E> {
 875         int cursor;       // index of next element to return
 876         int lastRet = -1; // index of last element returned; -1 if no such
 877         int expectedModCount = modCount;
 878 


 879         public boolean hasNext() {
 880             return cursor != size;
 881         }
 882 
 883         @SuppressWarnings("unchecked")
 884         public E next() {
 885             checkForComodification();
 886             int i = cursor;
 887             if (i >= size)
 888                 throw new NoSuchElementException();
 889             Object[] elementData = ArrayList.this.elementData;
 890             if (i >= elementData.length)
 891                 throw new ConcurrentModificationException();
 892             cursor = i + 1;
 893             return (E) elementData[lastRet = i];
 894         }
 895 
 896         public void remove() {
 897             if (lastRet < 0)
 898                 throw new IllegalStateException();




 859 
 860     /**
 861      * Returns an iterator over the elements in this list in proper sequence.
 862      *
 863      * <p>The returned iterator is <a href="#fail-fast"><i>fail-fast</i></a>.
 864      *
 865      * @return an iterator over the elements in this list in proper sequence
 866      */
 867     public Iterator<E> iterator() {
 868         return new Itr();
 869     }
 870 
 871     /**
 872      * An optimized version of AbstractList.Itr
 873      */
 874     private class Itr implements Iterator<E> {
 875         int cursor;       // index of next element to return
 876         int lastRet = -1; // index of last element returned; -1 if no such
 877         int expectedModCount = modCount;
 878 
 879         Itr() {}
 880 
 881         public boolean hasNext() {
 882             return cursor != size;
 883         }
 884 
 885         @SuppressWarnings("unchecked")
 886         public E next() {
 887             checkForComodification();
 888             int i = cursor;
 889             if (i >= size)
 890                 throw new NoSuchElementException();
 891             Object[] elementData = ArrayList.this.elementData;
 892             if (i >= elementData.length)
 893                 throw new ConcurrentModificationException();
 894             cursor = i + 1;
 895             return (E) elementData[lastRet = i];
 896         }
 897 
 898         public void remove() {
 899             if (lastRet < 0)
 900                 throw new IllegalStateException();


< prev index next >