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.69 by jsr166, Fri Aug 30 18:05:39 2019 UTC vs.
Revision 1.71 by jsr166, Fri Jul 24 20:57:26 2020 UTC

# Line 178 | Line 178 | public class ArrayList<E> extends Abstra
178       * @throws NullPointerException if the specified collection is null
179       */
180      public ArrayList(Collection<? extends E> c) {
181 <        elementData = c.toArray();
182 <        if ((size = elementData.length) != 0) {
183 <            // defend against c.toArray (incorrectly) not returning Object[]
184 <            // (see e.g. https://bugs.openjdk.java.net/browse/JDK-6260652)
185 <            if (elementData.getClass() != Object[].class)
186 <                elementData = Arrays.copyOf(elementData, size, Object[].class);
181 >        Object[] a = c.toArray();
182 >        if ((size = a.length) != 0) {
183 >            if (c.getClass() == ArrayList.class) {
184 >                elementData = a;
185 >            } else {
186 >                elementData = Arrays.copyOf(a, size, Object[].class);
187 >            }
188          } else {
189              // replace with empty array.
190 <            this.elementData = EMPTY_ELEMENTDATA;
190 >            elementData = EMPTY_ELEMENTDATA;
191          }
192      }
193  
# Line 1139 | Line 1140 | public class ArrayList<E> extends Abstra
1140              this.parent = parent;
1141              this.offset = parent.offset + fromIndex;
1142              this.size = toIndex - fromIndex;
1143 <            this.modCount = root.modCount;
1143 >            this.modCount = parent.modCount;
1144          }
1145  
1146          public E set(int index, E element) {
# Line 1292 | Line 1293 | public class ArrayList<E> extends Abstra
1293              return new ListIterator<E>() {
1294                  int cursor = index;
1295                  int lastRet = -1;
1296 <                int expectedModCount = root.modCount;
1296 >                int expectedModCount = SubList.this.modCount;
1297  
1298                  public boolean hasNext() {
1299                      return cursor != SubList.this.size;
# Line 1336 | Line 1337 | public class ArrayList<E> extends Abstra
1337                          final Object[] es = root.elementData;
1338                          if (offset + i >= es.length)
1339                              throw new ConcurrentModificationException();
1340 <                        for (; i < size && modCount == expectedModCount; i++)
1340 >                        for (; i < size && root.modCount == expectedModCount; i++)
1341                              action.accept(elementAt(es, offset + i));
1342                          // update once at end to reduce heap write traffic
1343                          cursor = i;
# Line 1362 | Line 1363 | public class ArrayList<E> extends Abstra
1363                          SubList.this.remove(lastRet);
1364                          cursor = lastRet;
1365                          lastRet = -1;
1366 <                        expectedModCount = root.modCount;
1366 >                        expectedModCount = SubList.this.modCount;
1367                      } catch (IndexOutOfBoundsException ex) {
1368                          throw new ConcurrentModificationException();
1369                      }
# Line 1388 | Line 1389 | public class ArrayList<E> extends Abstra
1389                          SubList.this.add(i, e);
1390                          cursor = i + 1;
1391                          lastRet = -1;
1392 <                        expectedModCount = root.modCount;
1392 >                        expectedModCount = SubList.this.modCount;
1393                      } catch (IndexOutOfBoundsException ex) {
1394                          throw new ConcurrentModificationException();
1395                      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines