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:
Shawn O. Pearce 2011-03-16 21:33:25 -07:00
parent 5aab335f45
commit 00a5040147
1 changed files with 6 additions and 1 deletions

View File

@ -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--;