ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/jsr166e/extra/ReadMostlyVector.java
(Generate patch)

Comparing jsr166/src/jsr166e/extra/ReadMostlyVector.java (file contents):
Revision 1.28 by dl, Fri Oct 12 14:09:35 2012 UTC vs.
Revision 1.33 by jsr166, Wed Jan 2 04:35:20 2013 UTC

# Line 14 | Line 14 | import java.util.*;
14   * throughput when invocations of read-only methods by multiple
15   * threads are most common.
16   *
17 < * <p> The iterators returned by this class's {@link #iterator()
17 > * <p>The iterators returned by this class's {@link #iterator()
18   * iterator} and {@link #listIterator(int) listIterator} methods are
19   * best-effort in the presence of concurrent modifications, and do
20   * <em>NOT</em> throw {@link ConcurrentModificationException}.  An
# Line 93 | Line 93 | public class ReadMostlyVector<E>
93       * Creates an empty vector with the given initial capacity.
94       *
95       * @param initialCapacity the initial capacity of the underlying array
96     *
96       * @throws IllegalArgumentException if initial capacity is negative
97       */
98      public ReadMostlyVector(int initialCapacity) {
# Line 158 | Line 157 | public class ReadMostlyVector<E>
157              else
158                  newCapacity = MAX_ARRAY_SIZE;
159          }
160 <        return array = ((items == null) ?
160 >        return array = ((items == null) ?
161                          new Object[newCapacity] :
162                          Arrays.copyOf(items, newCapacity));
163      }
# Line 172 | Line 171 | public class ReadMostlyVector<E>
171      static int findFirstIndex(Object[] items, Object x, int index, int fence) {
172          int len;
173          if (items != null && (len = items.length) > 0) {
174 <            int start = (index < 0)? 0 : index;
174 >            int start = (index < 0) ? 0 : index;
175              int bound = (fence < len) ? fence : len;
176              for (int i = start; i < bound; ++i) {
177                  Object e = items[i];
# Line 406 | Line 405 | public class ReadMostlyVector<E>
405                  sb.append('[');
406                  for (;;) {
407                      Object e = items[i];
408 <                    sb.append((e == this)? "(this Collection)" : e.toString());
408 >                    sb.append((e == this) ? "(this Collection)" : e.toString());
409                      if (++i < fence)
410                          sb.append(',').append(' ');
411                      else
# Line 427 | Line 426 | public class ReadMostlyVector<E>
426                  n = len;
427              int fence = bound < 0 || bound > n ? n : bound;
428              int i = (origin < 0) ? 0 : origin;
429 <            if (i != fence)
429 >            if (i != fence)
430                  return Arrays.copyOfRange(items, i, fence, Object[].class);
431          }
432          return new Object[0];
# Line 568 | Line 567 | public class ReadMostlyVector<E>
567          final StampedLock lock = this.lock;
568          long stamp = lock.tryOptimisticRead();
569          Object[] items;
570 <        if (index >= 0 && (items = array) != null &&
570 >        if (index >= 0 && (items = array) != null &&
571              index < count && index < items.length) {
572              @SuppressWarnings("unchecked") E e = (E)items[index];
573              if (lock.validate(stamp))
# Line 584 | Line 583 | public class ReadMostlyVector<E>
583          long stamp = lock.readLock();
584          try {
585              Object[] items;
586 <            if ((items = array) != null && index < items.length &&
586 >            if ((items = array) != null && index < items.length &&
587                  index < count && index >= 0)
588                  e = (E)items[index];
589              else
# Line 596 | Line 595 | public class ReadMostlyVector<E>
595              throw new ArrayIndexOutOfBoundsException(index);
596          return (E)e;
597      }
598 <    
598 >
599      public int hashCode() {
600          int h;
601          final StampedLock lock = this.lock;
# Line 608 | Line 607 | public class ReadMostlyVector<E>
607          }
608          return h;
609      }
610 <    
610 >
611      public int indexOf(Object o) {
612          int idx;
613          final StampedLock lock = this.lock;
# Line 743 | Line 742 | public class ReadMostlyVector<E>
742              if (ret != null)
743                  return ret;
744          }
745 <        
745 >
746          throw new ArrayIndexOutOfBoundsException(fromIndex < 0 ? fromIndex : toIndex);
747      }
748  
# Line 867 | Line 866 | public class ReadMostlyVector<E>
866          final StampedLock lock = this.lock;
867          long stamp = lock.readLock();
868          try {
869 <            Object[] items;
869 >            Object[] items;
870              int len, n;
871              if ((items = array) != null && (len = items.length) > 0 &&
872                  (n = count) <= len) {
# Line 921 | Line 920 | public class ReadMostlyVector<E>
920          long stamp = lock.tryOptimisticRead();
921          Object[] items;
922          int i;
923 <        if ((items = array) != null && (i = count - 1) >= 0 &&
923 >        if ((items = array) != null && (i = count - 1) >= 0 &&
924              i < items.length) {
925              @SuppressWarnings("unchecked") E e = (E)items[i];
926              if (lock.validate(stamp))
# Line 974 | Line 973 | public class ReadMostlyVector<E>
973          try {
974              if (index < count)
975                  idx = findLastIndex(array, o, index, 0);
976 <            else
976 >            else
977                  oobe = true;
978          } finally {
979              lock.unlockRead(stamp);
# Line 1039 | Line 1038 | public class ReadMostlyVector<E>
1038              long stamp = lock.writeLock();
1039              try {
1040                  Object[] items = array;
1041 <                int cap = (items == null)? 0 : items.length;
1041 >                int cap = (items == null) ? 0 : items.length;
1042                  if (minCapacity - cap > 0)
1043                      grow(minCapacity);
1044              } finally {
# Line 1248 | Line 1247 | public class ReadMostlyVector<E>
1247  
1248      static final class ReadMostlyVectorSublist<E>
1249              implements List<E>, RandomAccess, java.io.Serializable {
1250 <        static final long serialVersionUID = 3041673470172026059L;
1250 >        private static final long serialVersionUID = 3041673470172026059L;
1251  
1252          final ReadMostlyVector<E> list;
1253          final int offset;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines