You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zipkin.apache.org by GitBox <gi...@apache.org> on 2019/05/14 07:21:55 UTC

[GitHub] [incubator-zipkin] adriancole commented on a change in pull request #2591: Let Java copy arrays which it can sometimes do faster than manual loops.

adriancole commented on a change in pull request #2591: Let Java copy arrays which it can sometimes do faster than manual loops.
URL: https://github.com/apache/incubator-zipkin/pull/2591#discussion_r283657086
 
 

 ##########
 File path: zipkin/src/main/java/zipkin2/Span.java
 ##########
 @@ -659,11 +659,21 @@ public static String normalizeTraceId(String traceId) {
     }
   }
 
+  static final String THIRTY_TWO_ZEROS;
+  static {
+    char[] zeros = new char[32];
+    Arrays.fill(zeros, '0');
+    THIRTY_TWO_ZEROS = new String(zeros);
+  }
+
   static String padLeft(String id, int desiredLength) {
+    int length = id.length();
+    int numZeros = desiredLength - length;
+
     char[] data = Platform.shortStringBuffer();
-    int i = 0, length = id.length(), offset = desiredLength - length;
-    for (; i < offset; i++) data[i] = '0';
-    for (int j = 0; j < length; j++) data[i++] = id.charAt(j);
+    THIRTY_TWO_ZEROS.getChars(0, numZeros, data, 0);
+    id.getChars(0, length, data, numZeros);
 
 Review comment:
   heh never knew about this method before. nice one!

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services