Author: nbubna
Date: Mon Jul 28 19:56:00 2008
New Revision: 680609
URL: http://svn.apache.org/viewvc?rev=680609&view=rev
Log:
remove unnecessary synchronization (VELOCITY-606)
Modified:
velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/ClassMap.java
velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/IntrospectorBase.java
Modified:
velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/ClassMap.java
URL:
http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/ClassMap.java?rev=680609&r1=680608&r2=680609&view=diff
==============================================================================
---
velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/ClassMap.java
(original)
+++
velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/ClassMap.java
Mon Jul 28 19:56:00 2008
@@ -247,42 +247,35 @@
public Method get(final String name, final Object [] params)
throws MethodMap.AmbiguousException
{
- String methodKey = getLock(makeMethodKey(name, params));
-
- synchronized (methodKey)
+ Object cacheEntry = cache.get(makeMethodKey(name, params));
+ if (cacheEntry == CACHE_MISS)
{
- Object cacheEntry = cache.get(methodKey);
-
// We looked this up before and failed.
- if (cacheEntry == CACHE_MISS)
+ return null;
+ }
+
+ if (cacheEntry == null)
+ {
+ try
{
- return null;
+ // That one is expensive...
+ cacheEntry = methodMap.find(name, params);
}
-
- if (cacheEntry == null)
+ catch(MethodMap.AmbiguousException ae)
{
- try
- {
- // That one is expensive...
- cacheEntry = methodMap.find(name, params);
- }
- catch(MethodMap.AmbiguousException ae)
- {
- /*
- * that's a miss :-)
- */
- cache.put(methodKey, CACHE_MISS);
- throw ae;
- }
-
- cache.put(methodKey,
- (cacheEntry != null) ? cacheEntry : CACHE_MISS);
+ /*
+ * that's a miss :-)
+ */
+ cache.put(methodKey, CACHE_MISS);
+ throw ae;
}
- // Yes, this might just be null.
-
- return (Method) cacheEntry;
+ cache.put(methodKey,
+ (cacheEntry != null) ? cacheEntry : CACHE_MISS);
}
+
+ // Yes, this might just be null.
+ return (Method) cacheEntry;
}
private void put(Method method)
@@ -304,18 +297,6 @@
}
}
- private final String getLock(String key) {
- synchronized (locks)
- {
- String lock = (String)locks.get(key);
- if (lock == null)
- {
- return key;
- }
- return lock;
- }
- }
-
/**
* Make a methodKey for the given method using
* the concatenation of the name and the
Modified:
velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/IntrospectorBase.java
URL:
http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/IntrospectorBase.java?rev=680609&r1=680608&r2=680609&view=diff
==============================================================================
---
velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/IntrospectorBase.java
(original)
+++
velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/IntrospectorBase.java
Mon Jul 28 19:56:00 2008
@@ -96,18 +96,12 @@
throw new IllegalArgumentException("params object is null!");
}
- ClassMap classMap = null;
-
IntrospectorCache ic = getIntrospectorCache();
-
- synchronized(ic)
- {
- classMap = ic.get(c);
- if (classMap == null)
- {
- classMap = ic.put(c);
- }
+ ClassMap classMap = ic.get(c);
+ if (classMap == null)
+ {
+ classMap = ic.put(c);
}
return classMap.findMethod(name, params);