Replace alternating regex with character classes
This commit replaces two alternating regular expressions (that is, regular expressions that consist of the form a|b where a and b are characters) with the equivalent regular expression rewritten as a character class (that is, [ab]) The reason this is an improvement is because a|b involves backtracking while [ab] does not. Relates #24316
This commit is contained in:
parent
fc97e25b56
commit
3c845727f8
|
@ -196,7 +196,7 @@ public class Version implements Comparable<Version> {
|
||||||
if (snapshot = version.endsWith("-SNAPSHOT")) {
|
if (snapshot = version.endsWith("-SNAPSHOT")) {
|
||||||
version = version.substring(0, version.length() - 9);
|
version = version.substring(0, version.length() - 9);
|
||||||
}
|
}
|
||||||
String[] parts = version.split("\\.|\\-");
|
String[] parts = version.split("[.-]");
|
||||||
if (parts.length < 3 || parts.length > 4) {
|
if (parts.length < 3 || parts.length > 4) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"the version needs to contain major, minor, and revision, and optionally the build: " + version);
|
"the version needs to contain major, minor, and revision, and optionally the build: " + version);
|
||||||
|
|
|
@ -311,7 +311,7 @@ public class DeprecationLogger {
|
||||||
* @return the escaped string
|
* @return the escaped string
|
||||||
*/
|
*/
|
||||||
public static String escape(String s) {
|
public static String escape(String s) {
|
||||||
return s.replaceAll("(\\\\|\")", "\\\\$1");
|
return s.replaceAll("([\"\\\\])", "\\\\$1");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue