Skip to content

Commit

Permalink
Use much faster JDK utility for converting an int to a byte sequence.
Browse files Browse the repository at this point in the history
  • Loading branch information
CodingFabian committed Dec 17, 2015
1 parent 8bf2101 commit c7fa50e
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/main/java/com/lambdaworks/redis/protocol/CommandArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,21 +220,15 @@ private CommandArgs<K, V> 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));
}
}

Expand Down

0 comments on commit c7fa50e

Please sign in to comment.