Fixed a performance issue with utf8 characters.

When an utf8 char was detected in a string, jedis flushed its output buffer
for each char. Now, the buffer is only flushed when it is really full.
This commit is contained in:
Cyril Bonté
2010-10-09 20:46:50 +02:00
parent 3b880bba43
commit 3f21dcd0eb

View File

@@ -119,13 +119,13 @@ public final class RedisOutputStream extends FilterOutputStream {
flushBuffer();
}
} else if (c < 0x800) {
if(2 < buf.length - count) {
if(2 >= buf.length - count) {
flushBuffer();
}
buf[count++] = (byte)(0xc0 | (c >> 6));
buf[count++] = (byte)(0x80 | (c & 0x3f));
} else if (isSurrogate(c)) {
if(4 < buf.length - count) {
if(4 >= buf.length - count) {
flushBuffer();
}
int uc = Character.toCodePoint(c, str.charAt(i++));
@@ -134,7 +134,7 @@ public final class RedisOutputStream extends FilterOutputStream {
buf[count++] = ((byte)(0x80 | ((uc >> 6) & 0x3f)));
buf[count++] = ((byte)(0x80 | (uc & 0x3f)));
} else {
if(3 < buf.length - count) {
if(3 >= buf.length - count) {
flushBuffer();
}
buf[count++] =((byte)(0xe0 | ((c >> 12))));