Author: jason.greene(a)jboss.com
Date: 2008-07-30 19:52:09 -0400 (Wed, 30 Jul 2008)
New Revision: 6451
Modified:
core/trunk/src/main/java/org/jboss/cache/util/FastCopyHashMap.java
Log:
Better optimized copy constructor
Modified: core/trunk/src/main/java/org/jboss/cache/util/FastCopyHashMap.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/util/FastCopyHashMap.java 2008-07-30 23:46:45
UTC (rev 6450)
+++ core/trunk/src/main/java/org/jboss/cache/util/FastCopyHashMap.java 2008-07-30 23:52:09
UTC (rev 6451)
@@ -110,22 +110,26 @@
init(initialCapacity, loadFactor);
}
+ @SuppressWarnings("unchecked")
public FastCopyHashMap(Map<? extends K, ? extends V> map)
{
- this(map.size());
- putAll(map);
+ if (map instanceof FastCopyHashMap)
+ {
+ FastCopyHashMap<? extends K, ? extends V> fast = (FastCopyHashMap<?
extends K, ? extends V>) map;
+ this.table = (Entry<K, V>[])fast.table.clone();
+ this.loadFactor = fast.loadFactor;
+ this.size = fast.size;
+ this.threshold = fast.threshold;
+ }
+ else
+ {
+ this.loadFactor = DEFAULT_LOAD_FACTOR;
+ init(map.size(), this.loadFactor);
+ putAll(map);
+ }
}
@SuppressWarnings("unchecked")
- public FastCopyHashMap(FastCopyHashMap<? extends K, ? extends V> map)
- {
- this.table = (Entry<K, V>[])map.table.clone();
- this.loadFactor = map.loadFactor;
- this.size = map.size;
- this.threshold = map.threshold;
- }
-
- @SuppressWarnings("unchecked")
private void init(int initialCapacity, float loadFactor)
{
int c = 1;
Show replies by date