This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/8.5.x by this push:
new 19bc0c7ecf Speedup by removing non pattern replaceAll with constant arg
19bc0c7ecf is described below
commit 19bc0c7ecfd2cfb13a480c7ea954154244be3ec5
Author: Andrey Bruykhov <[email protected]>
AuthorDate: Thu Feb 2 15:38:32 2023 +0300
Speedup by removing non pattern replaceAll with constant arg
replaceAll("ABC", "") is non Pattern method and therefore must be
replaced to simple fast replace()
A proofs of changes:
https://gist.github.com/tbw777/8a6ef60af21487c5faec67037099fd0b
---
java/org/apache/catalina/startup/ClassLoaderFactory.java | 4 ++--
java/org/apache/tomcat/buildutil/translate/Utils.java | 2 +-
test/javax/el/TestImportHandlerStandardPackages.java | 2 +-
test/org/apache/tomcat/util/http/parser/TestMediaType.java | 2 +-
test/org/apache/tomcat/util/net/openssl/ciphers/TesterOpenSSL.java | 2 +-
webapps/docs/changelog.xml | 5 +++++
6 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/java/org/apache/catalina/startup/ClassLoaderFactory.java
b/java/org/apache/catalina/startup/ClassLoaderFactory.java
index 684b707e52..3b9df354c2 100644
--- a/java/org/apache/catalina/startup/ClassLoaderFactory.java
+++ b/java/org/apache/catalina/startup/ClassLoaderFactory.java
@@ -301,7 +301,7 @@ public final class ClassLoaderFactory {
// JARs. If these URLs are used to construct URLs for resources in a
JAR
// the URL will be used as is. It is therefore necessary to ensure that
// the sequence "!/" is not present in a class loader URL.
- String result = urlString.replaceAll("!/", "%21/");
+ String result = urlString.replace("!/", "%21/");
return new URI(result).toURL();
}
@@ -309,7 +309,7 @@ public final class ClassLoaderFactory {
private static URL buildClassLoaderUrl(File file) throws
MalformedURLException, URISyntaxException {
// Could be a directory or a file
String fileUrlString = file.toURI().toString();
- fileUrlString = fileUrlString.replaceAll("!/", "%21/");
+ fileUrlString = fileUrlString.replace("!/", "%21/");
return new URI(fileUrlString).toURL();
}
diff --git a/java/org/apache/tomcat/buildutil/translate/Utils.java
b/java/org/apache/tomcat/buildutil/translate/Utils.java
index 1daa6669db..658dfc0243 100644
--- a/java/org/apache/tomcat/buildutil/translate/Utils.java
+++ b/java/org/apache/tomcat/buildutil/translate/Utils.java
@@ -105,7 +105,7 @@ public class Utils {
result = ESCAPE_LEADING_SPACE.matcher(result).replaceAll("\\\\$1");
- result = result.replaceAll("\t", "\\t");
+ result = result.replace("\t", "\\t");
return result;
}
diff --git a/test/javax/el/TestImportHandlerStandardPackages.java
b/test/javax/el/TestImportHandlerStandardPackages.java
index 319922cb2e..f314a434f4 100644
--- a/test/javax/el/TestImportHandlerStandardPackages.java
+++ b/test/javax/el/TestImportHandlerStandardPackages.java
@@ -133,7 +133,7 @@ public class TestImportHandlerStandardPackages {
// Skip directories
continue;
}
- Class<?> clazz = Class.forName(packageName + "." +
name.replaceAll("\\.", "\\$"));
+ Class<?> clazz = Class.forName(packageName + "." +
name.replace(".", "$"));
if (!Modifier.isPublic(clazz.getModifiers())) {
// Skip non-public classes
continue;
diff --git a/test/org/apache/tomcat/util/http/parser/TestMediaType.java
b/test/org/apache/tomcat/util/http/parser/TestMediaType.java
index d4440fd31b..a0e19f740c 100644
--- a/test/org/apache/tomcat/util/http/parser/TestMediaType.java
+++ b/test/org/apache/tomcat/util/http/parser/TestMediaType.java
@@ -150,7 +150,7 @@ public class TestMediaType {
MediaType m = MediaType.parseMediaType(sr);
Assert.assertEquals(CHARSET_WS, m.getCharset());
- Assert.assertEquals(TYPES.replaceAll(" ", ""),
+ Assert.assertEquals(TYPES.replace(" ", ""),
m.toStringNoCharset());
}
diff --git a/test/org/apache/tomcat/util/net/openssl/ciphers/TesterOpenSSL.java
b/test/org/apache/tomcat/util/net/openssl/ciphers/TesterOpenSSL.java
index 4a9735f653..0df4cb26bb 100644
--- a/test/org/apache/tomcat/util/net/openssl/ciphers/TesterOpenSSL.java
+++ b/test/org/apache/tomcat/util/net/openssl/ciphers/TesterOpenSSL.java
@@ -276,7 +276,7 @@ public class TesterOpenSSL {
String ciphers[] = stdout.split("\n");
for (String cipher : ciphers) {
// Handle rename for 1.1.0 onwards
- cipher = cipher.replaceAll("EDH", "DHE");
+ cipher = cipher.replace("EDH", "DHE");
if (first) {
first = false;
} else {
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 4636c07074..f8aabefb51 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -111,6 +111,11 @@
Allow a Valve to access cookies from a request that cannot be mapped to
a Context. (markt)
</fix>
+ <fix>
+ Refactor uses of <code>String.replaceAll()</code> to use
+ <code>String.replace()</code> where regular expressions where not being
+ used. Pull request <pr>581</pr> provided by Andrei Briukhov. (markt)
+ </fix>
</changelog>
</subsection>
<subsection name="Coyote">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]