From c7fa50ef203fff04d2d3e16967e78f9dd49a88e5 Mon Sep 17 00:00:00 2001 From: Fabian Lange Date: Thu, 17 Dec 2015 00:21:43 +0100 Subject: [PATCH] Use much faster JDK utility for converting an int to a byte sequence. --- .../lambdaworks/redis/protocol/CommandArgs.java | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/lambdaworks/redis/protocol/CommandArgs.java b/src/main/java/com/lambdaworks/redis/protocol/CommandArgs.java index 0c32bfc7c7..2b87be435d 100644 --- a/src/main/java/com/lambdaworks/redis/protocol/CommandArgs.java +++ b/src/main/java/com/lambdaworks/redis/protocol/CommandArgs.java @@ -220,21 +220,15 @@ private CommandArgs write(String arg) { return this; } - private void write(long value) { + private void write(int value) { if (value < 10) { buffer.put((byte) ('0' + value)); return; } - StringBuilder sb = new StringBuilder(8); - while (value > 0) { - long digit = value % 10; - sb.append((char) ('0' + digit)); - value /= 10; - } - - for (int i = sb.length() - 1; i >= 0; i--) { - buffer.put((byte) sb.charAt(i)); + String asString = Integer.toString(value); + for (int i = 0; i < asString.length(); i++) { + buffer.put((byte) asString.charAt(i)); } }