forked from phoedos/pmd
Merge branch 'pr-130' into pmd/5.5.x
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@ -5,11 +5,10 @@ package net.sourceforge.pmd.lang.ast.xpath;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
|
||||
@ -49,8 +48,8 @@ public class AttributeAxisIterator implements Iterator<Attribute> {
|
||||
private int position;
|
||||
private Node node;
|
||||
|
||||
private static Map<Class<?>, MethodWrapper[]> methodCache =
|
||||
Collections.synchronizedMap(new HashMap<Class<?>, MethodWrapper[]>());
|
||||
private static ConcurrentMap<Class<?>, MethodWrapper[]> methodCache =
|
||||
new ConcurrentHashMap<Class<?>, MethodWrapper[]>();
|
||||
|
||||
public AttributeAxisIterator(Node contextNode) {
|
||||
this.node = contextNode;
|
||||
@ -62,7 +61,7 @@ public class AttributeAxisIterator implements Iterator<Attribute> {
|
||||
postFilter.add(new MethodWrapper(element));
|
||||
}
|
||||
}
|
||||
methodCache.put(contextNode.getClass(), postFilter.toArray(new MethodWrapper[postFilter.size()]));
|
||||
methodCache.putIfAbsent(contextNode.getClass(), postFilter.toArray(new MethodWrapper[postFilter.size()]));
|
||||
}
|
||||
this.methodWrappers = methodCache.get(contextNode.getClass());
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
package net.sourceforge.pmd.lang.rule.xpath;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -40,7 +40,15 @@ public class SaxonXPathRuleQuery extends AbstractXPathRuleQuery {
|
||||
// Mapping from Node name to applicable XPath queries
|
||||
private XPathExpression xpathExpression;
|
||||
private List<XPathVariable> xpathVariables;
|
||||
private static final Map<Node, DocumentNode> CACHE = new HashMap<>();
|
||||
|
||||
private static final int MAX_CACHE_SIZE = 20;
|
||||
private static final Map<Node, DocumentNode> CACHE = new LinkedHashMap<Node, DocumentNode>(MAX_CACHE_SIZE) {
|
||||
private static final long serialVersionUID = -7653916493967142443L;
|
||||
|
||||
protected boolean removeEldestEntry(final Map.Entry<Node, DocumentNode> eldest) {
|
||||
return size() > MAX_CACHE_SIZE;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@ -125,17 +133,12 @@ public class SaxonXPathRuleQuery extends AbstractXPathRuleQuery {
|
||||
root = root.jjtGetParent();
|
||||
}
|
||||
|
||||
// Cache DocumentNode trees, so that different XPath queries can re-use
|
||||
// them.
|
||||
// Ideally this would be an LRU cache.
|
||||
// Cache DocumentNode trees, so that different XPath queries can re-use them.
|
||||
DocumentNode documentNode;
|
||||
synchronized (CACHE) {
|
||||
documentNode = CACHE.get(root);
|
||||
if (documentNode == null) {
|
||||
documentNode = new DocumentNode(root);
|
||||
if (CACHE.size() > 20) {
|
||||
CACHE.clear();
|
||||
}
|
||||
CACHE.put(root, documentNode);
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,7 @@
|
||||
* [#127](https://github.com/pmd/pmd/pull/127): \[java] Don't look twice for the same variables
|
||||
* [#128](https://github.com/pmd/pmd/pull/128): \[java] Minor optimizations to type resolution
|
||||
* [#129](https://github.com/pmd/pmd/pull/129): \[plsql] Added correct parse of IS [NOT] NULL and multiline DML
|
||||
* [#130](https://github.com/pmd/pmd/pull/130); \[core] Reduce thread contention
|
||||
* [#135](https://github.com/pmd/pmd/pull/135): \[apex] New ruleset for Apex security
|
||||
|
||||
**Bugfixes:**
|
||||
|
Reference in New Issue
Block a user