[tor-commits] [metrics-lib/master] Avoid string concatenation in a loop.

karsten at torproject.org karsten at torproject.org
Mon Aug 27 12:33:54 UTC 2018


commit 273f3c2e13bbf7021b0758ddc52c0e8be071dd4c
Author: Karsten Loesing <karsten.loesing at gmx.net>
Date:   Mon Aug 20 20:27:24 2018 +0200

    Avoid string concatenation in a loop.
---
 src/main/java/org/torproject/descriptor/index/IndexNode.java | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/torproject/descriptor/index/IndexNode.java b/src/main/java/org/torproject/descriptor/index/IndexNode.java
index 02b5972..6852681 100644
--- a/src/main/java/org/torproject/descriptor/index/IndexNode.java
+++ b/src/main/java/org/torproject/descriptor/index/IndexNode.java
@@ -137,13 +137,13 @@ public class IndexNode {
       if (null == currentDir) {
         continue;
       }
-      String currentPath = dirs[0] + "/";
+      StringBuilder currentPath = new StringBuilder(dirs[0] + "/");
       for (int k = 1; k < dirs.length; k++) {
         DirectoryNode dn = findPathIn(dirs[k], currentDir.directories);
         if (null == dn) {
           break;
         } else {
-          currentPath += dirs[k] + "/";
+          currentPath.append(dirs[k]).append("/");
           currentDir = dn;
         }
       }
@@ -152,7 +152,7 @@ public class IndexNode {
       }
       for (FileNode file : currentDir.files) {
         if (file.lastModifiedMillis() > 0) { // only add valid files
-          map.put(currentPath + file.path, file);
+          map.put(currentPath.toString() + file.path, file);
         }
       }
     }





More information about the tor-commits mailing list