Factor out duplicate Inflater setup in WindowCursor

Since we use this code twice, pull it into a private method.  Let
the compiler/JIT worry about whether or not this logic should be
inlined into the call sites.

Change-Id: Ia44fb01e0328485bcdfd7af96835d62b227a0fb1
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
This commit is contained in:
Shawn O. Pearce 2010-05-15 16:18:44 -07:00
parent d8f20745bf
commit 9c4d42e94d
1 changed files with 9 additions and 8 deletions

View File

@ -116,10 +116,7 @@ int copy(final PackFile pack, long position, final byte[] dstbuf,
*/
int inflate(final PackFile pack, long position, final byte[] dstbuf,
int dstoff) throws IOException, DataFormatException {
if (inf == null)
inf = InflaterCache.get();
else
inf.reset();
prepareInflater();
for (;;) {
pin(pack, position);
dstoff = window.inflate(position, dstbuf, dstoff, inf);
@ -131,10 +128,7 @@ int inflate(final PackFile pack, long position, final byte[] dstbuf,
void inflateVerify(final PackFile pack, long position)
throws IOException, DataFormatException {
if (inf == null)
inf = InflaterCache.get();
else
inf.reset();
prepareInflater();
for (;;) {
pin(pack, position);
window.inflateVerify(position, inf);
@ -144,6 +138,13 @@ void inflateVerify(final PackFile pack, long position)
}
}
private void prepareInflater() {
if (inf == null)
inf = InflaterCache.get();
else
inf.reset();
}
private void pin(final PackFile pack, final long position)
throws IOException {
final ByteWindow w = window;