summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2010-02-12 07:00:32 -0800
committerShawn O. Pearce <spearce@spearce.org>2010-03-12 16:10:30 -0800
commit89cdc3b713c214a8f7142ef0d0df714027ad9876 (patch)
tree9bd13941aef7dc6266463452f55e87200d942ec7 /org.eclipse.jgit
parentc0f093899f8c027fb4e0f4418ac19b0f8ad6be16 (diff)
downloadjgit-89cdc3b713c214a8f7142ef0d0df714027ad9876.tar.gz
jgit-89cdc3b713c214a8f7142ef0d0df714027ad9876.zip
Reuse the line buffer between strings in PacketLineIn
When reading pkt-lines off an InputStream we are quite likely to consume a whole group of fairly short lines in rapid succession, such as in the have exchange that occurs in the fetch-pack/upload-pack protocol. Rather than allocating a throwaway buffer for each line's raw byte sequence, reuse a buffer that is equal to the small side-band packet size, which is 1000 bytes. Text based pkt-lines are required to be less than this size because many widely deployed versions of C Git use a statically allocated array of this length. Change-Id: Ia5c8e95b85020f7f80b6d269dda5059b092d274d Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java21
1 files changed, 13 insertions, 8 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 1022eb2ee1..170e4ddbe0 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008-2009, Google Inc.
+ * Copyright (C) 2008-2010, Google Inc.
* Copyright (C) 2008-2009, Robin Rosenberg <robin.rosenberg@dewire.com>
* Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
* and other copyright owners as documented in the project's IP log.
@@ -72,11 +72,11 @@ class PacketLineIn {
private final InputStream in;
- private final byte[] lenbuffer;
+ private final byte[] lineBuffer;
PacketLineIn(final InputStream i) {
in = i;
- lenbuffer = new byte[4];
+ lineBuffer = new byte[SideBandOutputStream.SMALL_BUF];
}
AckNackResult readACK(final MutableObjectId returnedId) throws IOException {
@@ -124,22 +124,27 @@ class PacketLineIn {
len -= 4; // length header (4 bytes)
- 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);
return RawParseUtils.decode(Constants.CHARSET, raw, 0, len);
}
int readLength() throws IOException {
- IO.readFully(in, lenbuffer, 0, 4);
+ IO.readFully(in, lineBuffer, 0, 4);
try {
- final int len = RawParseUtils.parseHexInt16(lenbuffer, 0);
+ final int len = RawParseUtils.parseHexInt16(lineBuffer, 0);
if (len != 0 && len < 4)
throw new ArrayIndexOutOfBoundsException();
return len;
} catch (ArrayIndexOutOfBoundsException err) {
throw new IOException("Invalid packet line header: "
- + (char) lenbuffer[0] + (char) lenbuffer[1]
- + (char) lenbuffer[2] + (char) lenbuffer[3]);
+ + (char) lineBuffer[0] + (char) lineBuffer[1]
+ + (char) lineBuffer[2] + (char) lineBuffer[3]);
}
}
}