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

Comparing jsr166/src/main/java/util/concurrent/ConcurrentHashMap.java (file contents):
Revision 1.71 by dl, Thu May 26 15:48:12 2005 UTC vs.
Revision 1.72 by dl, Sat May 28 13:31:22 2005 UTC

# Line 195 | Line 195 | public class ConcurrentHashMap<K, V> ext
195              this.next = next;
196              this.value = value;
197          }
198 +
199 +        @SuppressWarnings("unchecked")
200 +        static final <K,V> HashEntry<K,V>[] newArray(int i) {
201 +            return new HashEntry[i];
202 +        }
203      }
204  
205      /**
# Line 265 | Line 270 | public class ConcurrentHashMap<K, V> ext
270          transient int threshold;
271  
272          /**
273 <         * The per-segment table. Declared as a raw type, casted
269 <         * to HashEntry<K,V> on each use.
270 <         */
273 >         * The per-segment table. */
274          transient volatile HashEntry<K,V>[] table;
275  
276          /**
# Line 280 | Line 283 | public class ConcurrentHashMap<K, V> ext
283  
284          Segment(int initialCapacity, float lf) {
285              loadFactor = lf;
286 <            setTable(new HashEntry[initialCapacity]);
286 >            setTable(HashEntry.<K,V>newArray(initialCapacity));
287 >        }
288 >
289 >        @SuppressWarnings("unchecked")
290 >        static final <K,V> Segment<K,V>[] newArray(int i) {
291 >            return new Segment[i];
292          }
293  
294          /**
# Line 351 | Line 359 | public class ConcurrentHashMap<K, V> ext
359                  HashEntry<K,V>[] tab = table;
360                  int len = tab.length;
361                  for (int i = 0 ; i < len; i++) {
362 <                    for (HashEntry<K,V> e = (HashEntry<K,V>)tab[i];
355 <                         e != null ;
356 <                         e = e.next) {
362 >                    for (HashEntry<K,V> e = tab[i]; e != null; e = e.next) {
363                          V v = e.value;
364                          if (v == null) // recheck
365                              v = readValueUnderLock(e);
# Line 453 | Line 459 | public class ConcurrentHashMap<K, V> ext
459               * right now.
460               */
461  
462 <            HashEntry<K,V>[] newTable = (HashEntry<K,V>[])new HashEntry[oldCapacity << 1];
462 >            HashEntry<K,V>[] newTable = HashEntry.newArray(oldCapacity<<1);
463              threshold = (int)(newTable.length * loadFactor);
464              int sizeMask = newTable.length - 1;
465              for (int i = 0; i < oldCapacity ; i++) {
# Line 587 | Line 593 | public class ConcurrentHashMap<K, V> ext
593          }
594          segmentShift = 32 - sshift;
595          segmentMask = ssize - 1;
596 <        this.segments = (Segment<K,V>[]) new Segment[ssize];
596 >        this.segments = Segment.newArray(ssize);
597  
598          if (initialCapacity > MAXIMUM_CAPACITY)
599              initialCapacity = MAXIMUM_CAPACITY;
# Line 1321 | Line 1327 | public class ConcurrentHashMap<K, V> ext
1327  
1328          // Initialize each segment to be minimally sized, and let grow.
1329          for (int i = 0; i < segments.length; ++i) {
1330 <            segments[i].setTable(new HashEntry[1]);
1330 >            segments[i].setTable((HashEntry<K,V>[])HashEntry.newArray(1));
1331          }
1332  
1333          // Read the keys and values, and put the mappings in the table

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines