Skip to content

Commit 7b59107

Browse files
committed
Use faster replace methods
1 parent 7b726b0 commit 7b59107

File tree

18 files changed

+78
-78
lines changed

18 files changed

+78
-78
lines changed

src/main/java/com/laytonsmith/PureUtilities/ArgumentParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ public String toString() {
598598
b.append(", ");
599599
}
600600
first = false;
601-
b.append("\"").append(s.replaceAll("\"", "\\\"")).append("\"");
601+
b.append("\"").append(s.replace("\"", "\\\"")).append("\"");
602602
}
603603
b.append("]");
604604
}
@@ -642,7 +642,7 @@ private String generateDescription(boolean shortCode) {
642642
if(argType == Type.ARRAY_OF_STRINGS) {
643643
b.append("A list. ");
644644
}
645-
b.append(description.replaceAll("\n", "\n\t\t"));
645+
b.append(description.replace("\n", "\n\t\t"));
646646
}
647647
b.append("\n");
648648
}

src/main/java/com/laytonsmith/PureUtilities/ClassLoading/ClassDiscovery.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ public <T> ClassMirror<T> getMirrorFromClass(Class<T> clazz) throws NoClassDefFo
774774
ClassMirror<?> cm = classToMirrorCache.get(clazz);
775775
if(cm == null) {
776776
for(ClassMirror<?> m : getKnownClasses()) {
777-
if(m.getClassName().equals(clazz.getName().replace("$", "."))) {
777+
if(m.getClassName().equals(clazz.getName().replace('$', '.'))) {
778778
cm = m;
779779
classToMirrorCache.put(clazz, cm);
780780
break;
@@ -1171,7 +1171,7 @@ public static URL GetClassContainer(Class<?> c) {
11711171
String thisClass = c.getResource(c.getSimpleName() + ".class").toString();
11721172
try {
11731173
try {
1174-
packageRoot = StringUtils.replaceLast(thisClass, Pattern.quote(c.getName().replaceAll("\\.", "/") + ".class"), "");
1174+
packageRoot = StringUtils.replaceLast(thisClass, Pattern.quote(c.getName().replace('.', '/') + ".class"), "");
11751175
} catch (Exception e) {
11761176
//Hmm, ok, try this then
11771177
packageRoot = c.getProtectionDomain().getCodeSource().getLocation().toString();

src/main/java/com/laytonsmith/PureUtilities/Common/DateUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public static String ParseCalendarNotation(String name, Calendar c) {
4545
String hour = String.format("%02d", c.get(Calendar.HOUR));
4646
String minute = String.format("%02d", c.get(Calendar.MINUTE));
4747
String second = String.format("%02d", c.get(Calendar.SECOND));
48-
return name.replaceAll("%Y", year).replaceAll("%M", month)
49-
.replaceAll("%D", day).replaceAll("%h", hour)
50-
.replaceAll("%m", minute).replaceAll("%s", second);
48+
return name.replace("%Y", year).replace("%M", month)
49+
.replace("%D", day).replace("%h", hour)
50+
.replace("%m", minute).replace("%s", second);
5151
}
5252
}

src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCPlayer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ public void resetPlayerWeather() {
330330
@Override
331331
public void sendMessage(String string) {
332332
//The client doesn't like tabs
333-
string = string.replaceAll("\t", " ");
333+
string = string.replace("\t", " ");
334334
p.sendMessage(string);
335335
}
336336

src/main/java/com/laytonsmith/core/MethodScriptCompiler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public static TokenStream lex(String script, Environment env, File file,
165165
* this variable, to allow the lexer to make use of the file options already.
166166
*/
167167
FileOptions builtFileOptions = null;
168-
script = script.replaceAll("\r\n", "\n");
168+
script = script.replace("\r\n", "\n");
169169
script = script + "\n";
170170
final Set<String> keywords = KeywordList.getKeywordNames();
171171
final TokenStream tokenList = new TokenStream();
@@ -1016,7 +1016,7 @@ public static TokenStream lex(String script, Environment env, File file,
10161016
// Filename check
10171017
String fileName = tokenList.getFileOptions().getName();
10181018
if(!fileName.isEmpty()) {
1019-
if(!file.getAbsolutePath().replace("\\", "/").endsWith(fileName.replace("\\", "/"))) {
1019+
if(!file.getAbsolutePath().replace('\\', '/').endsWith(fileName.replace('\\', '/'))) {
10201020
CompilerWarning warning = new CompilerWarning(file + " has the wrong file name in the file options ("
10211021
+ fileName + ")", new Target(0, file, 0), null);
10221022
env.getEnv(CompilerEnvironment.class).addCompilerWarning(null, warning);

src/main/java/com/laytonsmith/core/Static.java

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,8 +1183,8 @@ public static boolean hasCHPermission(String functionName, Environment env) {
11831183
public static String Logo() {
11841184
String logo = Installer.parseISToString(Static.class.getResourceAsStream("/mainlogo"));
11851185
logo = logo.replaceAll("( +)", TermColors.BG_BLACK + "$1");
1186-
logo = logo.replaceAll("_", TermColors.BG_RED + TermColors.RED + "_");
1187-
logo = logo.replaceAll("/", TermColors.BG_BRIGHT_WHITE + TermColors.WHITE + "/");
1186+
logo = logo.replace("_", TermColors.BG_RED + TermColors.RED + "_");
1187+
logo = logo.replace("/", TermColors.BG_BRIGHT_WHITE + TermColors.WHITE + "/");
11881188
logo = logo.replace("\n", TermColors.reset() + "\n");
11891189
String s = logo + TermColors.reset();
11901190
return s;
@@ -1193,8 +1193,8 @@ public static String Logo() {
11931193
public static String DataManagerLogo() {
11941194
String logo = Installer.parseISToString(Static.class.getResourceAsStream("/datamanagerlogo"));
11951195
logo = logo.replaceAll("( +)", TermColors.BG_BLACK + "$1");
1196-
logo = logo.replaceAll("_", TermColors.CYAN + TermColors.BG_CYAN + "_");
1197-
logo = logo.replaceAll("/", TermColors.BG_WHITE + TermColors.WHITE + "/");
1196+
logo = logo.replace("_", TermColors.CYAN + TermColors.BG_CYAN + "_");
1197+
logo = logo.replace("/", TermColors.BG_WHITE + TermColors.WHITE + "/");
11981198
String s = logo + TermColors.reset();
11991199
return s;
12001200
}
@@ -1220,28 +1220,28 @@ public static String MCToANSIColors(String mes) {
12201220
}
12211221
return mes
12221222
.replaceAll("(?i)§x(§[a-f0-9]){6}", "")
1223-
.replaceAll("§0", TermColors.BLACK)
1224-
.replaceAll("§1", TermColors.BLUE)
1225-
.replaceAll("§2", TermColors.GREEN)
1226-
.replaceAll("§3", TermColors.CYAN)
1227-
.replaceAll("§4", TermColors.RED)
1228-
.replaceAll("§5", TermColors.MAGENTA)
1229-
.replaceAll("§6", TermColors.YELLOW)
1230-
.replaceAll("§7", TermColors.WHITE)
1231-
.replaceAll("§8", TermColors.BRIGHT_BLACK)
1232-
.replaceAll("§9", TermColors.BRIGHT_BLUE)
1233-
.replaceAll("§a", TermColors.BRIGHT_GREEN)
1234-
.replaceAll("§b", TermColors.BRIGHT_CYAN)
1235-
.replaceAll("§c", TermColors.BRIGHT_RED)
1236-
.replaceAll("§d", TermColors.BRIGHT_MAGENTA)
1237-
.replaceAll("§e", TermColors.BRIGHT_YELLOW)
1238-
.replaceAll("§f", TermColors.BRIGHT_WHITE)
1239-
.replaceAll("§k", "") //Uh, no equivalent for "random"
1240-
.replaceAll("§l", TermColors.BOLD)
1241-
.replaceAll("§m", TermColors.STRIKE)
1242-
.replaceAll("§n", TermColors.UNDERLINE)
1243-
.replaceAll("§o", TermColors.ITALIC)
1244-
.replaceAll("§r", TermColors.RESET);
1223+
.replace("§0", TermColors.BLACK)
1224+
.replace("§1", TermColors.BLUE)
1225+
.replace("§2", TermColors.GREEN)
1226+
.replace("§3", TermColors.CYAN)
1227+
.replace("§4", TermColors.RED)
1228+
.replace("§5", TermColors.MAGENTA)
1229+
.replace("§6", TermColors.YELLOW)
1230+
.replace("§7", TermColors.WHITE)
1231+
.replace("§8", TermColors.BRIGHT_BLACK)
1232+
.replace("§9", TermColors.BRIGHT_BLUE)
1233+
.replace("§a", TermColors.BRIGHT_GREEN)
1234+
.replace("§b", TermColors.BRIGHT_CYAN)
1235+
.replace("§c", TermColors.BRIGHT_RED)
1236+
.replace("§d", TermColors.BRIGHT_MAGENTA)
1237+
.replace("§e", TermColors.BRIGHT_YELLOW)
1238+
.replace("§f", TermColors.BRIGHT_WHITE)
1239+
.replace("§k", "") //Uh, no equivalent for "random"
1240+
.replace("§l", TermColors.BOLD)
1241+
.replace("§m", TermColors.STRIKE)
1242+
.replace("§n", TermColors.UNDERLINE)
1243+
.replace("§o", TermColors.ITALIC)
1244+
.replace("§r", TermColors.RESET);
12451245

12461246
}
12471247

src/main/java/com/laytonsmith/core/constructs/CClosure.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ private void condense(ParseTree node, StringBuilder b) {
107107
} else if(node.getData().isInstanceOf(CString.TYPE)) {
108108
String data = ArgumentValidation.getString(node.getData(), node.getTarget());
109109
// Convert: \ -> \\ and ' -> \'
110-
b.append("'").append(data.replace("\\", "\\\\").replaceAll("\t", "\\\\t").replaceAll("\n", "\\\\n")
110+
b.append("'").append(data.replace("\\", "\\\\").replace("\t", "\\t").replace("\n", "\\n")
111111
.replace("'", "\\'")).append("'");
112112
} else if(node.getData() instanceof IVariable) {
113113
b.append(((IVariable) node.getData()).getVariableName());

src/main/java/com/laytonsmith/core/functions/DataHandling.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1756,7 +1756,7 @@ public String symbolDisplayName(List<ParseTree> children) {
17561756
if(value instanceof CString) {
17571757
builder.append("'")
17581758
.append(value.val().replace("\\", "\\\\")
1759-
.replaceAll("\t", "\\\\t").replaceAll("\n", "\\\\n")
1759+
.replace("\t", "\\t").replace("\n", "\\n")
17601760
.replace("'", "\\'"))
17611761
.append("'");
17621762
} else {

src/main/java/com/laytonsmith/core/functions/Environment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1534,7 +1534,7 @@ public Mixed exec(Target t, com.laytonsmith.core.environments.Environment enviro
15341534
}
15351535
String ttone = ((CArray) args[noteOffset]).get("tone", t).val().toUpperCase().trim();
15361536
try {
1537-
tone = MCTone.valueOf(ttone.trim().replaceAll("#", ""));
1537+
tone = MCTone.valueOf(ttone.trim().replace("#", ""));
15381538
} catch (IllegalArgumentException e) {
15391539
throw new CREFormatException("Expected the tone parameter to be one of: "
15401540
+ StringUtils.Join(MCTone.values(), ", ", ", or ") + " but it was " + ttone, t);

src/main/java/com/laytonsmith/core/functions/Scheduling.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ private CronFormat validateFormat(String format, Target t) {
989989
//Our goal here is to remove all ranges, predefined names, including @hourly and January.
990990
format = format.trim();
991991
//Changes tabs to spaces
992-
format = format.replace("\t", " ");
992+
format = format.replace('\t', ' ');
993993
//Change multiple spaces to one space
994994
format = format.replaceAll("( )+", " ");
995995
//Lowercase everything

0 commit comments

Comments
 (0)