提交 7d307b38 编写于 作者: J Juergen Hoeller

Polishing

上级 fcb9dd19
...@@ -1192,12 +1192,17 @@ public final class ResolvableType implements Serializable { ...@@ -1192,12 +1192,17 @@ public final class ResolvableType implements Serializable {
if (type == null) { if (type == null) {
return NONE; return NONE;
} }
// Check the cache, we may have a ResolvableType that may have already been resolved
// Purge empty entries on access since we don't have a clean-up thread or the like.
cache.purgeUnreferencedEntries(); cache.purgeUnreferencedEntries();
// For simple Class references, build the wrapper right away -
// no expensive resolution necessary, so not worth caching...
if (type instanceof Class<?>) { if (type instanceof Class<?>) {
return new ResolvableType(type, typeProvider, variableResolver, null); return new ResolvableType(type, typeProvider, variableResolver, null);
} }
// Check the cache - we may have a ResolvableType which has been resolved before...
ResolvableType key = new ResolvableType(type, typeProvider, variableResolver); ResolvableType key = new ResolvableType(type, typeProvider, variableResolver);
ResolvableType resolvableType = cache.get(key); ResolvableType resolvableType = cache.get(key);
if (resolvableType == null) { if (resolvableType == null) {
......
...@@ -58,7 +58,9 @@ public class AntPathMatcher implements PathMatcher { ...@@ -58,7 +58,9 @@ public class AntPathMatcher implements PathMatcher {
private static final Pattern VARIABLE_PATTERN = Pattern.compile("\\{[^/]+?\\}"); private static final Pattern VARIABLE_PATTERN = Pattern.compile("\\{[^/]+?\\}");
private String pathSeparator = DEFAULT_PATH_SEPARATOR; private String pathSeparator;
private PathSeparatorPatternCache pathSeparatorPatternCache;
private boolean trimTokens = true; private boolean trimTokens = true;
...@@ -68,13 +70,13 @@ public class AntPathMatcher implements PathMatcher { ...@@ -68,13 +70,13 @@ public class AntPathMatcher implements PathMatcher {
final Map<String, AntPathStringMatcher> stringMatcherCache = new ConcurrentHashMap<String, AntPathStringMatcher>(256); final Map<String, AntPathStringMatcher> stringMatcherCache = new ConcurrentHashMap<String, AntPathStringMatcher>(256);
private PathSeparatorPatternCache pathSeparatorPatternCache = new PathSeparatorPatternCache(DEFAULT_PATH_SEPARATOR);
/** /**
* Create a new instance with the {@link #DEFAULT_PATH_SEPARATOR}. * Create a new instance with the {@link #DEFAULT_PATH_SEPARATOR}.
*/ */
public AntPathMatcher() { public AntPathMatcher() {
this.pathSeparator = DEFAULT_PATH_SEPARATOR;
this.pathSeparatorPatternCache = new PathSeparatorPatternCache(DEFAULT_PATH_SEPARATOR);
} }
/** /**
...@@ -580,14 +582,13 @@ public class AntPathMatcher implements PathMatcher { ...@@ -580,14 +582,13 @@ public class AntPathMatcher implements PathMatcher {
* {@link #getPatternComparator(String)}. * {@link #getPatternComparator(String)}.
* <p>In order, the most "generic" pattern is determined by the following: * <p>In order, the most "generic" pattern is determined by the following:
* <ul> * <ul>
* <li>if it's null or a capture all pattern (i.e. it is equal to "/**")</li> * <li>if it's null or a capture all pattern (i.e. it is equal to "/**")</li>
* <li>if the other pattern is an actual match</li> * <li>if the other pattern is an actual match</li>
* <li>if it's a catch-all pattern (i.e. it ends with "**"</li> * <li>if it's a catch-all pattern (i.e. it ends with "**"</li>
* <li>if it's got more "*" than the other pattern</li> * <li>if it's got more "*" than the other pattern</li>
* <li>if it's got more "{foo}" than the other pattern</li> * <li>if it's got more "{foo}" than the other pattern</li>
* <li>if it's shorter than the other pattern</li> * <li>if it's shorter than the other pattern</li>
* </ul> * </ul>
* </p>
*/ */
protected static class AntPatternComparator implements Comparator<String> { protected static class AntPatternComparator implements Comparator<String> {
...@@ -598,15 +599,13 @@ public class AntPathMatcher implements PathMatcher { ...@@ -598,15 +599,13 @@ public class AntPathMatcher implements PathMatcher {
} }
/** /**
* Compare two patterns to determine which should match first, i.e. which is the most specific * Compare two patterns to determine which should match first, i.e. which
* regarding the current path. * is the most specific regarding the current path.
*
* @return a negative integer, zero, or a positive integer as pattern1 is * @return a negative integer, zero, or a positive integer as pattern1 is
* more specific, equally specific, or less specific than pattern2. * more specific, equally specific, or less specific than pattern2.
*/ */
@Override @Override
public int compare(String pattern1, String pattern2) { public int compare(String pattern1, String pattern2) {
PatternInfo info1 = new PatternInfo(pattern1); PatternInfo info1 = new PatternInfo(pattern1);
PatternInfo info2 = new PatternInfo(pattern2); PatternInfo info2 = new PatternInfo(pattern2);
...@@ -664,6 +663,7 @@ public class AntPathMatcher implements PathMatcher { ...@@ -664,6 +663,7 @@ public class AntPathMatcher implements PathMatcher {
return 0; return 0;
} }
/** /**
* Value class that holds information about the pattern, e.g. number of * Value class that holds information about the pattern, e.g. number of
* occurrences of "*", "**", and "{" pattern elements. * occurrences of "*", "**", and "{" pattern elements.
...@@ -684,7 +684,6 @@ public class AntPathMatcher implements PathMatcher { ...@@ -684,7 +684,6 @@ public class AntPathMatcher implements PathMatcher {
private Integer length; private Integer length;
public PatternInfo(String pattern) { public PatternInfo(String pattern) {
this.pattern = pattern; this.pattern = pattern;
if (this.pattern != null) { if (this.pattern != null) {
...@@ -769,8 +768,7 @@ public class AntPathMatcher implements PathMatcher { ...@@ -769,8 +768,7 @@ public class AntPathMatcher implements PathMatcher {
private final String endsOnDoubleWildCard; private final String endsOnDoubleWildCard;
public PathSeparatorPatternCache(String pathSeparator) {
private PathSeparatorPatternCache(String pathSeparator) {
this.endsOnWildCard = pathSeparator + "*"; this.endsOnWildCard = pathSeparator + "*";
this.endsOnDoubleWildCard = pathSeparator + "**"; this.endsOnDoubleWildCard = pathSeparator + "**";
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册