lazily allocate the LZF buffer if its only needed
This commit is contained in:
parent
a3b21b884c
commit
8b9aa1fd27
|
@ -34,19 +34,26 @@ public class CachedStreamOutput {
|
||||||
private static Entry newEntry() {
|
private static Entry newEntry() {
|
||||||
BytesStreamOutput bytes = new BytesStreamOutput();
|
BytesStreamOutput bytes = new BytesStreamOutput();
|
||||||
HandlesStreamOutput handles = new HandlesStreamOutput(bytes);
|
HandlesStreamOutput handles = new HandlesStreamOutput(bytes);
|
||||||
LZFStreamOutput lzf = new LZFStreamOutput(bytes, true);
|
return new Entry(bytes, handles);
|
||||||
return new Entry(bytes, handles, lzf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Entry {
|
public static class Entry {
|
||||||
private final BytesStreamOutput bytes;
|
private final BytesStreamOutput bytes;
|
||||||
private final HandlesStreamOutput handles;
|
private final HandlesStreamOutput handles;
|
||||||
private final LZFStreamOutput lzf;
|
private LZFStreamOutput lzf;
|
||||||
|
|
||||||
Entry(BytesStreamOutput bytes, HandlesStreamOutput handles, LZFStreamOutput lzf) {
|
Entry(BytesStreamOutput bytes, HandlesStreamOutput handles) {
|
||||||
this.bytes = bytes;
|
this.bytes = bytes;
|
||||||
this.handles = handles;
|
this.handles = handles;
|
||||||
this.lzf = lzf;
|
}
|
||||||
|
|
||||||
|
// lazily initialize LZF, so we won't allocate it if we don't do
|
||||||
|
// any compression
|
||||||
|
private LZFStreamOutput lzf() {
|
||||||
|
if (lzf == null) {
|
||||||
|
lzf = new LZFStreamOutput(bytes, true);
|
||||||
|
}
|
||||||
|
return lzf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -65,11 +72,13 @@ public class CachedStreamOutput {
|
||||||
}
|
}
|
||||||
|
|
||||||
public LZFStreamOutput cachedLZFBytes() throws IOException {
|
public LZFStreamOutput cachedLZFBytes() throws IOException {
|
||||||
|
LZFStreamOutput lzf = lzf();
|
||||||
lzf.reset();
|
lzf.reset();
|
||||||
return lzf;
|
return lzf;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HandlesStreamOutput cachedHandlesLzfBytes() throws IOException {
|
public HandlesStreamOutput cachedHandlesLzfBytes() throws IOException {
|
||||||
|
LZFStreamOutput lzf = lzf();
|
||||||
handles.reset(lzf);
|
handles.reset(lzf);
|
||||||
return handles;
|
return handles;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue