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:
Koen De Groote 2017-04-26 04:15:00 +02:00 committed by Jason Tedor
parent fc97e25b56
commit 3c845727f8
2 changed files with 2 additions and 2 deletions

View File

@ -196,7 +196,7 @@ public class Version implements Comparable<Version> {
if (snapshot = version.endsWith("-SNAPSHOT")) {
version = version.substring(0, version.length() - 9);
}
String[] parts = version.split("\\.|\\-");
String[] parts = version.split("[.-]");
if (parts.length < 3 || parts.length > 4) {
throw new IllegalArgumentException(
"the version needs to contain major, minor, and revision, and optionally the build: " + version);

View File

@ -311,7 +311,7 @@ public class DeprecationLogger {
* @return the escaped string
*/
public static String escape(String s) {
return s.replaceAll("(\\\\|\")", "\\\\$1");
return s.replaceAll("([\"\\\\])", "\\\\$1");
}
}