jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r995487 - in /jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name: HashCache.java NameElement.java NameFactoryImpl.java
Date Thu, 09 Sep 2010 16:43:52 GMT
Author: jukka
Date: Thu Sep  9 16:43:52 2010
New Revision: 995487

URL: http://svn.apache.org/viewvc?rev=995487&view=rev
Log:
JCR-2744: Avoid element arrays in PathImpl

Generify the HashCache class

Modified:
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/HashCache.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameElement.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameFactoryImpl.java

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/HashCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/HashCache.java?rev=995487&r1=995486&r2=995487&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/HashCache.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/HashCache.java
Thu Sep  9 16:43:52 2010
@@ -25,13 +25,13 @@ package org.apache.jackrabbit.spi.common
  *
  * @see https://issues.apache.org/jira/browse/JCR-1663
  */
-public class HashCache {
+public class HashCache<T> {
 
     /**
      * Array of cached objects, indexed by their hash codes
      * (module size of the array).
      */
-    private final Object[] array;
+    private final T[] array;
 
     /**
      * Creates a hash cache with 1024 slots.
@@ -45,8 +45,9 @@ public class HashCache {
      *
      * @param exponent the exponent.
      */
+    @SuppressWarnings("unchecked")
     public HashCache(int exponent) {
-        this.array = new Object[2 << exponent];
+        this.array = (T[]) new Object[2 << exponent];
     }
 
     /**
@@ -56,9 +57,9 @@ public class HashCache {
      * @param object object to return from the cache
      * @return the given object or a previously cached copy
      */
-    public Object get(Object object) {
+    public T get(T object) {
         int position = object.hashCode() & (array.length - 1);
-        Object previous = array[position];
+        T previous = array[position];
         if (object.equals(previous)) {
             return previous;
         } else {

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameElement.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameElement.java?rev=995487&r1=995486&r2=995487&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameElement.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameElement.java
Thu Sep  9 16:43:52 2010
@@ -29,7 +29,8 @@ final class NameElement extends Abstract
     private static final long serialVersionUID = -6655583285077651379L;
 
     /** Static cache of instances of this class. */
-    private static final HashCache cache = new HashCache();
+    private static final HashCache<NameElement> cache =
+        new HashCache<NameElement>();
 
     /**
      * Creates and returns a named path element. A cache of path elements
@@ -42,7 +43,7 @@ final class NameElement extends Abstract
     public static NameElement create(Name name, int index) {
         NameElement element = new NameElement(name, index);
         if (index == Path.INDEX_UNDEFINED) {
-            return (NameElement) cache.get(element);
+            return cache.get(element);
         } else {
             return element;
         }

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameFactoryImpl.java?rev=995487&r1=995486&r2=995487&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameFactoryImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameFactoryImpl.java
Thu Sep  9 16:43:52 2010
@@ -31,7 +31,7 @@ public class NameFactoryImpl implements 
      *
      * @see <a href="https://issues.apache.org/jira/browse/JCR-1663">JCR-1663</a>
      */
-    private final HashCache cache = new HashCache();
+    private final HashCache<Name> cache = new HashCache<Name>();
 
     private NameFactoryImpl() {};
 
@@ -51,7 +51,7 @@ public class NameFactoryImpl implements 
         if (localName == null) {
             throw new IllegalArgumentException("No localName specified");
         }
-        return (Name) cache.get(new NameImpl(namespaceURI, localName));
+        return cache.get(new NameImpl(namespaceURI, localName));
     }
 
     /**



Mime
View raw message