From 7d307b38534b9a04c37491ffef4628a4dd41e596 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 30 Sep 2014 20:17:58 +0200 Subject: [PATCH] Polishing --- .../springframework/core/ResolvableType.java | 7 +++- .../springframework/util/AntPathMatcher.java | 32 +++++++++---------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/ResolvableType.java b/spring-core/src/main/java/org/springframework/core/ResolvableType.java index 16cd8c4792..78c7e88f30 100644 --- a/spring-core/src/main/java/org/springframework/core/ResolvableType.java +++ b/spring-core/src/main/java/org/springframework/core/ResolvableType.java @@ -1192,12 +1192,17 @@ public final class ResolvableType implements Serializable { if (type == null) { 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(); + // For simple Class references, build the wrapper right away - + // no expensive resolution necessary, so not worth caching... if (type instanceof Class) { 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 resolvableType = cache.get(key); if (resolvableType == null) { diff --git a/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java b/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java index 1253ec8d1f..ff2056ab62 100644 --- a/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java +++ b/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java @@ -58,7 +58,9 @@ public class AntPathMatcher implements PathMatcher { private static final Pattern VARIABLE_PATTERN = Pattern.compile("\\{[^/]+?\\}"); - private String pathSeparator = DEFAULT_PATH_SEPARATOR; + private String pathSeparator; + + private PathSeparatorPatternCache pathSeparatorPatternCache; private boolean trimTokens = true; @@ -68,13 +70,13 @@ public class AntPathMatcher implements PathMatcher { final Map stringMatcherCache = new ConcurrentHashMap(256); - private PathSeparatorPatternCache pathSeparatorPatternCache = new PathSeparatorPatternCache(DEFAULT_PATH_SEPARATOR); - /** * Create a new instance with the {@link #DEFAULT_PATH_SEPARATOR}. */ public AntPathMatcher() { + this.pathSeparator = DEFAULT_PATH_SEPARATOR; + this.pathSeparatorPatternCache = new PathSeparatorPatternCache(DEFAULT_PATH_SEPARATOR); } /** @@ -580,14 +582,13 @@ public class AntPathMatcher implements PathMatcher { * {@link #getPatternComparator(String)}. *

In order, the most "generic" pattern is determined by the following: *

    - *
  • if it's null or a capture all pattern (i.e. it is equal to "/**")
  • - *
  • if the other pattern is an actual match
  • - *
  • if it's a catch-all pattern (i.e. it ends with "**"
  • - *
  • if it's got more "*" than the other pattern
  • - *
  • if it's got more "{foo}" than the other pattern
  • - *
  • if it's shorter than the other pattern
  • + *
  • if it's null or a capture all pattern (i.e. it is equal to "/**")
  • + *
  • if the other pattern is an actual match
  • + *
  • if it's a catch-all pattern (i.e. it ends with "**"
  • + *
  • if it's got more "*" than the other pattern
  • + *
  • if it's got more "{foo}" than the other pattern
  • + *
  • if it's shorter than the other pattern
  • *
- *

*/ protected static class AntPatternComparator implements Comparator { @@ -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 - * regarding the current path. - * + * Compare two patterns to determine which should match first, i.e. which + * is the most specific regarding the current path. * @return a negative integer, zero, or a positive integer as pattern1 is * more specific, equally specific, or less specific than pattern2. */ @Override public int compare(String pattern1, String pattern2) { - PatternInfo info1 = new PatternInfo(pattern1); PatternInfo info2 = new PatternInfo(pattern2); @@ -664,6 +663,7 @@ public class AntPathMatcher implements PathMatcher { return 0; } + /** * Value class that holds information about the pattern, e.g. number of * occurrences of "*", "**", and "{" pattern elements. @@ -684,7 +684,6 @@ public class AntPathMatcher implements PathMatcher { private Integer length; - public PatternInfo(String pattern) { this.pattern = pattern; if (this.pattern != null) { @@ -769,8 +768,7 @@ public class AntPathMatcher implements PathMatcher { private final String endsOnDoubleWildCard; - - private PathSeparatorPatternCache(String pathSeparator) { + public PathSeparatorPatternCache(String pathSeparator) { this.endsOnWildCard = pathSeparator + "*"; this.endsOnDoubleWildCard = pathSeparator + "**"; }