Skip to content

Commit 7d307b3

Browse files
committed
Polishing
1 parent fcb9dd1 commit 7d307b3

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

spring-core/src/main/java/org/springframework/core/ResolvableType.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1192,12 +1192,17 @@ static ResolvableType forType(Type type, TypeProvider typeProvider, VariableReso
11921192
if (type == null) {
11931193
return NONE;
11941194
}
1195-
// Check the cache, we may have a ResolvableType that may have already been resolved
1195+
1196+
// Purge empty entries on access since we don't have a clean-up thread or the like.
11961197
cache.purgeUnreferencedEntries();
11971198

1199+
// For simple Class references, build the wrapper right away -
1200+
// no expensive resolution necessary, so not worth caching...
11981201
if (type instanceof Class<?>) {
11991202
return new ResolvableType(type, typeProvider, variableResolver, null);
12001203
}
1204+
1205+
// Check the cache - we may have a ResolvableType which has been resolved before...
12011206
ResolvableType key = new ResolvableType(type, typeProvider, variableResolver);
12021207
ResolvableType resolvableType = cache.get(key);
12031208
if (resolvableType == null) {

spring-core/src/main/java/org/springframework/util/AntPathMatcher.java

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ public class AntPathMatcher implements PathMatcher {
5858
private static final Pattern VARIABLE_PATTERN = Pattern.compile("\\{[^/]+?\\}");
5959

6060

61-
private String pathSeparator = DEFAULT_PATH_SEPARATOR;
61+
private String pathSeparator;
62+
63+
private PathSeparatorPatternCache pathSeparatorPatternCache;
6264

6365
private boolean trimTokens = true;
6466

@@ -68,13 +70,13 @@ public class AntPathMatcher implements PathMatcher {
6870

6971
final Map<String, AntPathStringMatcher> stringMatcherCache = new ConcurrentHashMap<String, AntPathStringMatcher>(256);
7072

71-
private PathSeparatorPatternCache pathSeparatorPatternCache = new PathSeparatorPatternCache(DEFAULT_PATH_SEPARATOR);
72-
7373

7474
/**
7575
* Create a new instance with the {@link #DEFAULT_PATH_SEPARATOR}.
7676
*/
7777
public AntPathMatcher() {
78+
this.pathSeparator = DEFAULT_PATH_SEPARATOR;
79+
this.pathSeparatorPatternCache = new PathSeparatorPatternCache(DEFAULT_PATH_SEPARATOR);
7880
}
7981

8082
/**
@@ -580,14 +582,13 @@ public boolean matchStrings(String str, Map<String, String> uriTemplateVariables
580582
* {@link #getPatternComparator(String)}.
581583
* <p>In order, the most "generic" pattern is determined by the following:
582584
* <ul>
583-
* <li>if it's null or a capture all pattern (i.e. it is equal to "/**")</li>
584-
* <li>if the other pattern is an actual match</li>
585-
* <li>if it's a catch-all pattern (i.e. it ends with "**"</li>
586-
* <li>if it's got more "*" than the other pattern</li>
587-
* <li>if it's got more "{foo}" than the other pattern</li>
588-
* <li>if it's shorter than the other pattern</li>
585+
* <li>if it's null or a capture all pattern (i.e. it is equal to "/**")</li>
586+
* <li>if the other pattern is an actual match</li>
587+
* <li>if it's a catch-all pattern (i.e. it ends with "**"</li>
588+
* <li>if it's got more "*" than the other pattern</li>
589+
* <li>if it's got more "{foo}" than the other pattern</li>
590+
* <li>if it's shorter than the other pattern</li>
589591
* </ul>
590-
* </p>
591592
*/
592593
protected static class AntPatternComparator implements Comparator<String> {
593594

@@ -598,15 +599,13 @@ public AntPatternComparator(String path) {
598599
}
599600

600601
/**
601-
* Compare two patterns to determine which should match first, i.e. which is the most specific
602-
* regarding the current path.
603-
*
602+
* Compare two patterns to determine which should match first, i.e. which
603+
* is the most specific regarding the current path.
604604
* @return a negative integer, zero, or a positive integer as pattern1 is
605605
* more specific, equally specific, or less specific than pattern2.
606606
*/
607607
@Override
608608
public int compare(String pattern1, String pattern2) {
609-
610609
PatternInfo info1 = new PatternInfo(pattern1);
611610
PatternInfo info2 = new PatternInfo(pattern2);
612611

@@ -664,6 +663,7 @@ else if (info2.getUriVars() < info1.getUriVars()) {
664663
return 0;
665664
}
666665

666+
667667
/**
668668
* Value class that holds information about the pattern, e.g. number of
669669
* occurrences of "*", "**", and "{" pattern elements.
@@ -684,7 +684,6 @@ private static class PatternInfo {
684684

685685
private Integer length;
686686

687-
688687
public PatternInfo(String pattern) {
689688
this.pattern = pattern;
690689
if (this.pattern != null) {
@@ -769,8 +768,7 @@ private static class PathSeparatorPatternCache {
769768

770769
private final String endsOnDoubleWildCard;
771770

772-
773-
private PathSeparatorPatternCache(String pathSeparator) {
771+
public PathSeparatorPatternCache(String pathSeparator) {
774772
this.endsOnWildCard = pathSeparator + "*";
775773
this.endsOnDoubleWildCard = pathSeparator + "**";
776774
}

0 commit comments

Comments
 (0)