openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1307350 - /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java
Date Fri, 30 Mar 2012 10:35:53 GMT
Author: struberg
Date: Fri Mar 30 10:35:53 2012
New Revision: 1307350

URL: http://svn.apache.org/viewvc?rev=1307350&view=rev
Log:
OWB-639 use hash instead of String operations to calc the cacheKey

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java?rev=1307350&r1=1307349&r2=1307350&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java
Fri Mar 30 10:35:53 2012
@@ -68,12 +68,15 @@ public class InjectionResolver
      * Bean Manager
      */
     private WebBeansContext webBeansContext;
+    
+    private final static Annotation[] DEFAULT_LITERAL_ARRAY = new Annotation[]{new DefaultLiteral()};
 
     /**
      * This Map contains all resolved beans via it's type and qualifiers.
      * If a bean have resolved as not existing, the entry will contain <code>null</code>
as value.
+     * The Long key is a hashCode, see {@link #getBeanCacheKey(Type, String, Annotation...)}
      */
-    private Map<String, Set<Bean<?>>> resolvedBeansByType = new ConcurrentHashMap<String,
Set<Bean<?>>>();
+    private Map<Long, Set<Bean<?>>> resolvedBeansByType = new ConcurrentHashMap<Long,
Set<Bean<?>>>();
 
     /**
      * This Map contains all resolved beans via it's ExpressionLanguage name.
@@ -449,8 +452,7 @@ public class InjectionResolver
             bdaBeansXMLFilePath = getBDABeansXMLPath(injectinPointClass);
         }
 
-        //X TODO maybe we need to stringify the qualifiers manually im a loop...
-        String cacheKey = getBeanCacheKey(injectionPointType, bdaBeansXMLFilePath, qualifiers);
+        Long cacheKey = getBeanCacheKey(injectionPointType, bdaBeansXMLFilePath, qualifiers);
 
         Set<Bean<?>> resolvedComponents = resolvedBeansByType.get(cacheKey);
         if (resolvedComponents != null)
@@ -472,7 +474,7 @@ public class InjectionResolver
         {
             if (qualifiers.length == 0)
             {
-                qualifiers = new Annotation[]{new DefaultLiteral()};
+                qualifiers = DEFAULT_LITERAL_ARRAY;
                 currentQualifier = true;
             }
         }
@@ -524,18 +526,21 @@ public class InjectionResolver
         return resolvedComponents;
     }
 
-    private String getBeanCacheKey(Type injectionPointType, String bdaBeansXMLPath, Annotation...
qualifiers)
+    private Long getBeanCacheKey(Type injectionPointType, String bdaBeansXMLPath, Annotation...
qualifiers)
     {
-        StringBuilder cacheKey = new StringBuilder(injectionPointType.toString());
+
+        long cacheKey = injectionPointType.hashCode();
         if (bdaBeansXMLPath != null)
         {
-            cacheKey.append('@').append(bdaBeansXMLPath);
+            cacheKey += 29L * bdaBeansXMLPath.hashCode();
         }
         for (Annotation a : qualifiers)
         {
-            cacheKey.append('@').append(a.toString());
+            // we need to toString as the hashCode of an Annotation is always 0 :(
+            // and the annotationType does not contain variable payload
+            cacheKey += 29L * a.toString().hashCode();
         }
-        return cacheKey.toString();
+        return cacheKey;
     }
 
     /**



Mime
View raw message