Improve performance of ConcurrentReferenceHashMap creation
This commit is contained in:
parent
93189a6733
commit
112cc70231
|
@ -179,10 +179,13 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
|
|||
int size = 1 << this.shift;
|
||||
this.referenceType = referenceType;
|
||||
int roundedUpSegmentCapacity = (int) ((initialCapacity + size - 1L) / size);
|
||||
this.segments = (Segment[]) Array.newInstance(Segment.class, size);
|
||||
for (int i = 0; i < this.segments.length; i++) {
|
||||
this.segments[i] = new Segment(roundedUpSegmentCapacity);
|
||||
int initialSize = 1 << calculateShift(roundedUpSegmentCapacity, MAXIMUM_SEGMENT_SIZE);
|
||||
Segment[] segments = (Segment[]) Array.newInstance(Segment.class, size);
|
||||
int resizeThreshold = (int) (initialSize * getLoadFactor());
|
||||
for (int i = 0; i < segments.length; i++) {
|
||||
segments[i] = new Segment(initialSize, resizeThreshold);
|
||||
}
|
||||
this.segments = segments;
|
||||
}
|
||||
|
||||
|
||||
|
@ -481,11 +484,11 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
|
|||
*/
|
||||
private int resizeThreshold;
|
||||
|
||||
public Segment(int initialCapacity) {
|
||||
public Segment(int initialSize, int resizeThreshold) {
|
||||
this.referenceManager = createReferenceManager();
|
||||
this.initialSize = 1 << calculateShift(initialCapacity, MAXIMUM_SEGMENT_SIZE);
|
||||
this.references = createReferenceArray(this.initialSize);
|
||||
this.resizeThreshold = (int) (this.references.length * getLoadFactor());
|
||||
this.initialSize = initialSize;
|
||||
this.references = createReferenceArray(initialSize);
|
||||
this.resizeThreshold = resizeThreshold;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
|
Loading…
Reference in New Issue