[jbosscache-commits] JBoss Cache SVN: r5598 - experimental/jsr166/src/jsr166y.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Fri Apr 18 18:56:25 EDT 2008


Author: jason.greene at jboss.com
Date: 2008-04-18 18:56:25 -0400 (Fri, 18 Apr 2008)
New Revision: 5598

Modified:
   experimental/jsr166/src/jsr166y/ConcurrentReferenceHashMap.java
   experimental/jsr166/src/jsr166y/MapLoops.java
Log:
remove use of switch on enums in favor of faster reference checking
drop the 2 type refs on hashentry since it is space critical



Modified: experimental/jsr166/src/jsr166y/ConcurrentReferenceHashMap.java
===================================================================
--- experimental/jsr166/src/jsr166y/ConcurrentReferenceHashMap.java	2008-04-18 16:26:54 UTC (rev 5597)
+++ experimental/jsr166/src/jsr166y/ConcurrentReferenceHashMap.java	2008-04-18 22:56:25 UTC (rev 5598)
@@ -309,38 +309,31 @@
         final int hash;
         volatile Object valueRef;
         final HashEntry<K,V> next;
-        final ReferenceType keyType;
-        final ReferenceType valueType;
 
         HashEntry(K key, int hash,  HashEntry<K,V> next, V value, 
                 ReferenceType keyType, ReferenceType valueType, 
                 ReferenceQueue<K> refQueue) {
-            this.keyType = keyType;
-            this.valueType = valueType;
-            this.keyRef = newKeyReference(key, hash, refQueue);
+            this.keyRef = newKeyReference(key, keyType, hash, refQueue);
             this.hash = hash;
             this.next = next;
-            this.valueRef = newValueReference(value);
+            this.valueRef = newValueReference(value, valueType);
         }
         
-        final Object newKeyReference(K key, int hash, ReferenceQueue<K> refQueue) {
-            switch (keyType) {
-                case WEAK:
-                    return new WeakKeyReference<K>(key, hash, refQueue);
-                case SOFT:
-                    return new SoftKeyReference<K>(key, hash, refQueue);
-            }
+        final Object newKeyReference(K key, ReferenceType keyType, int hash, 
+                ReferenceQueue<K> refQueue) {
+            if (keyType == ReferenceType.WEAK)
+                return new WeakKeyReference<K>(key, hash, refQueue);
+            if (keyType == ReferenceType.SOFT)
+                return new SoftKeyReference<K>(key, hash, refQueue);
             
             return key;
         }
         
-        final Object newValueReference(V value) {
-            switch (valueType) {
-                case WEAK:
-                    return new WeakReference<V>(value);
-                case SOFT:
-                    return new SoftReference<V>(value);
-            }
+        final Object newValueReference(V value, ReferenceType valueType) {
+            if (valueType == ReferenceType.WEAK)
+                return new WeakReference<V>(value);
+            if (valueType == ReferenceType.SOFT)
+                return new SoftReference<V>(value);
             
             return value;
         }
@@ -365,8 +358,8 @@
             return (V) value;
         }
         
-        final void setValue(V value) {
-            this.valueRef = newValueReference(value);
+        final void setValue(V value, ReferenceType valueType) {
+            this.valueRef = newValueReference(value, valueType);
         }
 
         @SuppressWarnings("unchecked")
@@ -588,7 +581,7 @@
                 boolean replaced = false;
                 if (e != null && oldValue.equals(e.value())) {
                     replaced = true;
-                    e.setValue(newValue);
+                    e.setValue(newValue, valueType);
                 }
                 return replaced;
             } finally {
@@ -607,7 +600,7 @@
                 V oldValue = null;
                 if (e != null) {
                     oldValue = e.value();
-                    e.setValue(newValue);
+                    e.setValue(newValue, valueType);
                 }
                 return oldValue;
             } finally {
@@ -638,7 +631,7 @@
                 if (e != null) {
                     oldValue = e.value();
                     if (!onlyIfAbsent)
-                        e.setValue(value);
+                        e.setValue(value, valueType);
                 }
                 else {
                     oldValue = null;

Modified: experimental/jsr166/src/jsr166y/MapLoops.java
===================================================================
--- experimental/jsr166/src/jsr166y/MapLoops.java	2008-04-18 16:26:54 UTC (rev 5597)
+++ experimental/jsr166/src/jsr166y/MapLoops.java	2008-04-18 22:56:25 UTC (rev 5598)
@@ -48,7 +48,7 @@
             }
         }
         else
-            mapClass = ConcurrentWeakHashMap.class;
+            mapClass = ConcurrentReferenceHashMap.class;
 
         if (args.length > 1)
             maxThreads = Integer.parseInt(args[1]);




More information about the jbosscache-commits mailing list