PacketLineIn: Reuse internal lineBuffer for small strings
Most "ACK %s continue", "ACK %s common", "NAK" strings that are read by the readACK() method and readString() are shorter than the lineBuffer already available. Reuse that buffer when reading from the network stream and converting to a string with RawParseUtils to avoid unnecessary temporary byte array allocations. Change-Id: Ibc778d9f7721943a065041d80fc427ea50d90fff Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
This commit is contained in:
parent
5aab335f45
commit
00a5040147
|
@ -113,7 +113,12 @@ String readString() throws IOException {
|
|||
if (len == 0)
|
||||
return "";
|
||||
|
||||
final byte[] raw = new byte[len];
|
||||
byte[] raw;
|
||||
if (len <= lineBuffer.length)
|
||||
raw = lineBuffer;
|
||||
else
|
||||
raw = new byte[len];
|
||||
|
||||
IO.readFully(in, raw, 0, len);
|
||||
if (raw[len - 1] == '\n')
|
||||
len--;
|
||||
|
|
Loading…
Reference in New Issue