Skip to content
Snippets Groups Projects
Commit 9c4d42e9 authored by Shawn Pearce's avatar Shawn Pearce
Browse files

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: default avatarShawn O. Pearce <spearce@spearce.org>
parent d8f20745
No related branches found
No related tags found
No related merge requests found
...@@ -116,10 +116,7 @@ int copy(final PackFile pack, long position, final byte[] dstbuf, ...@@ -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 inflate(final PackFile pack, long position, final byte[] dstbuf,
int dstoff) throws IOException, DataFormatException { int dstoff) throws IOException, DataFormatException {
if (inf == null) prepareInflater();
inf = InflaterCache.get();
else
inf.reset();
for (;;) { for (;;) {
pin(pack, position); pin(pack, position);
dstoff = window.inflate(position, dstbuf, dstoff, inf); dstoff = window.inflate(position, dstbuf, dstoff, inf);
...@@ -131,10 +128,7 @@ int inflate(final PackFile pack, long position, final byte[] dstbuf, ...@@ -131,10 +128,7 @@ int inflate(final PackFile pack, long position, final byte[] dstbuf,
void inflateVerify(final PackFile pack, long position) void inflateVerify(final PackFile pack, long position)
throws IOException, DataFormatException { throws IOException, DataFormatException {
if (inf == null) prepareInflater();
inf = InflaterCache.get();
else
inf.reset();
for (;;) { for (;;) {
pin(pack, position); pin(pack, position);
window.inflateVerify(position, inf); window.inflateVerify(position, inf);
...@@ -144,6 +138,13 @@ void inflateVerify(final PackFile pack, long position) ...@@ -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) private void pin(final PackFile pack, final long position)
throws IOException { throws IOException {
final ByteWindow w = window; final ByteWindow w = window;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment