Avoid some array copies on STOMP decode

This commit is contained in:
Ville Skyttä 2015-07-16 13:23:58 +03:00 committed by Clebert Suconic
parent 94f84c43aa
commit 8a90de6fbc
3 changed files with 4 additions and 17 deletions

View File

@ -35,10 +35,8 @@ public class SimpleBytes
public String getString() public String getString()
{ {
if (index == 0) return ""; if (index == 0) return "";
byte[] realData = new byte[index];
System.arraycopy(contents, 0, realData, 0, realData.length);
return new String(realData, StandardCharsets.UTF_8); return new String(contents, 0, index, StandardCharsets.UTF_8);
} }
public void reset() public void reset()

View File

@ -312,11 +312,7 @@ public class StompDecoder
{ {
if (inHeaderName) if (inHeaderName)
{ {
byte[] data = new byte[pos - headerBytesCopyStart - 1]; headerName = new String(workingBuffer, headerBytesCopyStart, pos - headerBytesCopyStart - 1);
System.arraycopy(workingBuffer, headerBytesCopyStart, data, 0, data.length);
headerName = new String(data);
inHeaderName = false; inHeaderName = false;
@ -339,11 +335,7 @@ public class StompDecoder
break outer; break outer;
} }
byte[] data = new byte[pos - headerBytesCopyStart - 1]; String headerValue = new String(workingBuffer, headerBytesCopyStart, pos - headerBytesCopyStart - 1);
System.arraycopy(workingBuffer, headerBytesCopyStart, data, 0, data.length);
String headerValue = new String(data);
headers.put(headerName, headerValue); headers.put(headerName, headerValue);

View File

@ -229,10 +229,7 @@ public class StompFrame
iBuffer++; iBuffer++;
} }
char[] total = new char[iBuffer]; return new String(buffer, 0, iBuffer);
System.arraycopy(buffer, 0, total, 0, iBuffer);
return new String(total);
} }
public void setBody(String body) public void setBody(String body)