forked from phoedos/pmd
Use atomic operations on concurrentmap
- Take the chance to actually use the lazy loading
This commit is contained in:
@ -6,8 +6,8 @@ package net.sourceforge.pmd.lang.ast.xpath;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@ -20,7 +20,7 @@ public class Attribute {
|
||||
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(Attribute.class.getName());
|
||||
private static final Map<String, Boolean> DETECTED_DEPRECATED_ATTRIBUTES = new ConcurrentHashMap<>();
|
||||
private static final ConcurrentMap<String, Boolean> DETECTED_DEPRECATED_ATTRIBUTES = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
private static final Object[] EMPTY_OBJ_ARRAY = new Object[0];
|
||||
@ -48,14 +48,14 @@ public class Attribute {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (method.isAnnotationPresent(Deprecated.class) && LOG.isLoggable(Level.WARNING) && !DETECTED_DEPRECATED_ATTRIBUTES.containsKey(getLoggableAttributeName())) {
|
||||
DETECTED_DEPRECATED_ATTRIBUTES.put(getLoggableAttributeName(), Boolean.TRUE);
|
||||
if (method.isAnnotationPresent(Deprecated.class) && LOG.isLoggable(Level.WARNING)
|
||||
&& DETECTED_DEPRECATED_ATTRIBUTES.putIfAbsent(getLoggableAttributeName(), Boolean.TRUE) == null) {
|
||||
LOG.warning("Use of deprecated attribute '" + getLoggableAttributeName() + "' in xpath query");
|
||||
}
|
||||
|
||||
// this lazy loading reduces calls to Method.invoke() by about 90%
|
||||
try {
|
||||
return method.invoke(parent, EMPTY_OBJ_ARRAY);
|
||||
return value = method.invoke(parent, EMPTY_OBJ_ARRAY);
|
||||
} catch (IllegalAccessException | InvocationTargetException iae) {
|
||||
iae.printStackTrace();
|
||||
}
|
||||
|
Reference in New Issue
Block a user