[tor-commits] [exonerator/master] since no regex involved, replace() should be faster than replaceAll() since no Pattern.compile().matcher() will be needed behind the scenes

karsten at torproject.org karsten at torproject.org
Tue Feb 25 19:34:12 UTC 2020


commit 3a764fd3a5aa6ef0f4b0ad6c24c4e7f14bd2ec2c
Author: tordinge <tordinge at aprivatesub.net>
Date:   Mon Feb 24 20:35:51 2020 -0500

    since no regex involved, replace() should be faster than replaceAll() since no Pattern.compile().matcher() will be needed behind the scenes
---
 .../torproject/metrics/exonerator/ExoneraTorDatabaseImporter.java   | 6 +++---
 .../java/org/torproject/metrics/exonerator/ExoneraTorServlet.java   | 4 ++--
 src/main/java/org/torproject/metrics/exonerator/QueryServlet.java   | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/main/java/org/torproject/metrics/exonerator/ExoneraTorDatabaseImporter.java b/src/main/java/org/torproject/metrics/exonerator/ExoneraTorDatabaseImporter.java
index 2f39f5a..1e5f3bb 100644
--- a/src/main/java/org/torproject/metrics/exonerator/ExoneraTorDatabaseImporter.java
+++ b/src/main/java/org/torproject/metrics/exonerator/ExoneraTorDatabaseImporter.java
@@ -228,7 +228,7 @@ public class ExoneraTorDatabaseImporter {
         try {
           fingerprintBase64 = Base64.encodeBase64String(
               Hex.decodeHex(entry.getFingerprint().toCharArray()))
-              .replaceAll("=", "");
+              .replace("=", "");
         } catch (DecoderException e) {
           logger.warn("Unable to decode hex fingerprint {} to convert it back "
               + "to base64. Aborting import.", entry.getFingerprint(), e);
@@ -295,7 +295,7 @@ public class ExoneraTorDatabaseImporter {
                 + "s", "0"));
             if (!addressHexString.contains("x")
                 && addressHexString.length() == 32) {
-              orAddress24 = addressHexString.replaceAll(" ", "0")
+              orAddress24 = addressHexString.replace(" ", "0")
                   .toLowerCase().substring(0, 6);
             }
           }
@@ -327,7 +327,7 @@ public class ExoneraTorDatabaseImporter {
         try {
           fingerprintBase64 = Base64.encodeBase64String(
               Hex.decodeHex(entry.getFingerprint().toCharArray()))
-              .replaceAll("=", "");
+              .replace("=", "");
         } catch (DecoderException ex) {
           logger.warn("Unable to decode hex fingerprint {} to convert to "
               + "base64. Aborting import.", entry.getFingerprint(), ex);
diff --git a/src/main/java/org/torproject/metrics/exonerator/ExoneraTorServlet.java b/src/main/java/org/torproject/metrics/exonerator/ExoneraTorServlet.java
index 3ba42da..06fa0f5 100644
--- a/src/main/java/org/torproject/metrics/exonerator/ExoneraTorServlet.java
+++ b/src/main/java/org/torproject/metrics/exonerator/ExoneraTorServlet.java
@@ -480,7 +480,7 @@ public class ExoneraTorServlet extends HttpServlet {
       if (addressInSameNetwork.contains(":")) {
         address = addressInSameNetwork.replaceAll("[\\[\\]]", "");
         link = String.format("%s?ip=[%s]&timestamp=%s&lang=%s",
-            requestUri, address.replaceAll(":", "%3A"), timestampStr, langStr);
+            requestUri, address.replace(":", "%3A"), timestampStr, langStr);
         address = "[" + address + "]";
       } else {
         link = String.format("%s?ip=%s&timestamp=%s&lang=%s",
@@ -609,7 +609,7 @@ public class ExoneraTorServlet extends HttpServlet {
       String permanentLinkUrl, String relayIp, String timestampStr,
       String langStr) {
     String encodedAddress = relayIp.contains(":")
-        ? "[" + relayIp.replaceAll(":", "%3A") + "]" : relayIp;
+        ? "[" + relayIp.replace(":", "%3A") + "]" : relayIp;
     out.printf("      <div class=\"row\">\n"
         + "        <div class=\"col-xs-12\">\n"
         + "          <h2>%s</h2>\n"
diff --git a/src/main/java/org/torproject/metrics/exonerator/QueryServlet.java b/src/main/java/org/torproject/metrics/exonerator/QueryServlet.java
index 85dec57..ee61e28 100644
--- a/src/main/java/org/torproject/metrics/exonerator/QueryServlet.java
+++ b/src/main/java/org/torproject/metrics/exonerator/QueryServlet.java
@@ -214,7 +214,7 @@ public class QueryServlet extends HttpServlet {
           + "s", "0"));
       if (!addressHexString.contains("x")
           && addressHexString.length() == 32) {
-        address48 = addressHexString.replaceAll(" ", "0")
+        address48 = addressHexString.replace(" ", "0")
             .toLowerCase();
       }
     }





More information about the tor-commits mailing list