You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by GitBox <gi...@apache.org> on 2022/02/25 16:16:09 UTC

[GitHub] [httpcomponents-client] ok2c commented on a change in pull request #352: Optimize ExecSupport.getNextExchangeId()

ok2c commented on a change in pull request #352:
URL: https://github.com/apache/httpcomponents-client/pull/352#discussion_r814901897



##########
File path: httpclient5/src/main/java/org/apache/hc/client5/http/impl/ExecSupport.java
##########
@@ -45,7 +45,29 @@ public static long getNextExecNumber() {
     }
 
     public static String getNextExchangeId() {
-        return String.format("ex-%010d", COUNT.incrementAndGet());
+        return createId(COUNT.incrementAndGet());
+    }
+
+    /**
+     * Create an exchange ID.
+     *
+     * Hand rolled equivalent to `String.format("ex-%010d", value)` optimized to reduce
+     * allocation and CPU overhead.
+     */
+    static String createId(long value) {
+        String longString = Long.toString(value);
+        return "ex-" + zeroPad(10 - longString.length()) + longString;

Review comment:
       @carterkozak That would be clever.




-- 
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.

To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org