Browse Source

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>
stable-0.12
Shawn O. Pearce 14 years ago
parent
commit
00a5040147
  1. 7
      org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java

7
org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java

@ -113,7 +113,12 @@ class PacketLineIn {
if (len == 0) if (len == 0)
return ""; 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); IO.readFully(in, raw, 0, len);
if (raw[len - 1] == '\n') if (raw[len - 1] == '\n')
len--; len--;

Loading…
Cancel
Save