Browse Source

b64 encoding optimization

master
Nikita 11 years ago
parent
commit
62fadaeab1
  1. 13
      src/main/java/com/corundumstudio/socketio/protocol/PacketEncoder.java

13
src/main/java/com/corundumstudio/socketio/protocol/PacketEncoder.java

@ -54,11 +54,14 @@ public class PacketEncoder {
}
public void encodeJsonP(Integer jsonpIndex, Queue<Packet> packets, ByteBuf out, ByteBufAllocator allocator, int limit) throws IOException {
int i = 0;
ByteBuf buf = allocateBuffer(allocator);
boolean jsonpMode = jsonpIndex != null;
ByteBuf buf = out;
if (jsonpMode) {
buf = allocateBuffer(allocator);
}
int i = 0;
while (true) {
Packet packet = packets.poll();
if (packet == null || i == limit) {
@ -92,11 +95,7 @@ public class PacketEncoder {
packet = QUOTES_PATTERN.matcher(packet).replaceAll("\\\\\"");
packet = new String(packet.getBytes(CharsetUtil.UTF_8), CharsetUtil.ISO_8859_1);
out.writeBytes(packet.getBytes(CharsetUtil.UTF_8));
} else {
out.writeBytes(buf);
}
if (jsonpMode) {
out.writeBytes(JSONP_END);
}
}

Loading…
Cancel
Save