diff options
author | Shawn O. Pearce <spearce@spearce.org> | 2011-03-16 21:33:25 -0700 |
---|---|---|
committer | Shawn O. Pearce <spearce@spearce.org> | 2011-03-17 10:48:05 -0700 |
commit | 00a50401478171b900b5f1ea16c43618293706ce (patch) | |
tree | a620fb887b25b9a8b59dcbbf4001576c35f75094 | |
parent | 5aab335f45760dce16350d10c8788f204a032206 (diff) | |
download | jgit-00a50401478171b900b5f1ea16c43618293706ce.tar.gz jgit-00a50401478171b900b5f1ea16c43618293706ce.zip |
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>
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java index d3264d5f23..01d92770bc 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java @@ -113,7 +113,12 @@ class PacketLineIn { 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--; |