Skip to content

Commit da34491

Browse files
committed
Improve perf of 'literal*' glob
1 parent ede09b7 commit da34491

File tree

1 file changed

+10
-4
lines changed
  • libs/core/src/main/java/org/elasticsearch/core

1 file changed

+10
-4
lines changed

libs/core/src/main/java/org/elasticsearch/core/Glob.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,20 @@ public static boolean globMatch(String pattern, String str) {
3636
return pattern.equals(str);
3737
}
3838

39-
// If the pattern is a literal '*' then it matches any input
4039
if (patternIndex == 0) {
40+
// If the pattern is a literal '*' then it matches any input
4141
if (pattern.length() == 1) {
4242
return true;
4343
}
44-
} else if (str.regionMatches(0, pattern, 0, patternIndex) == false) {
45-
// If the pattern starts with a literal (i.e. not '*') then the input string must also start with that
46-
return false;
44+
} else {
45+
if (str.regionMatches(0, pattern, 0, patternIndex) == false) {
46+
// If the pattern starts with a literal (i.e. not '*') then the input string must also start with that
47+
return false;
48+
}
49+
if (patternIndex == pattern.length() - 1) {
50+
// The pattern is "something*", so if the starting region matches, then the whole pattern matches
51+
return true;
52+
}
4753
}
4854

4955
int strIndex = patternIndex;

0 commit comments

Comments
 (0)