LUCENE-6090: use raw deflate stream for CompressionMode.HIGH_COMPRESSION

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1643075 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2014-12-03 10:09:14 +00:00
parent 778e1b31ab
commit 8e1d811e09
2 changed files with 13 additions and 5 deletions

View File

@ -117,6 +117,9 @@ New Features
* LUCENE-6077: Added a filter cache. (Adrien Grand, Robert Muir)
* LUCENE-6089, LUCENE-6090: Tune CompressionMode.HIGH_COMPRESSION for
better compression and less cpu usage. (Adrien Grand, Robert Muir)
API Changes
* LUCENE-5900: Deprecated more constructors taking Version in *InfixSuggester and

View File

@ -186,7 +186,7 @@ public abstract class CompressionMode {
byte[] compressed;
DeflateDecompressor() {
decompressor = new Inflater();
decompressor = new Inflater(true);
compressed = new byte[0];
}
@ -198,13 +198,18 @@ public abstract class CompressionMode {
return;
}
final int compressedLength = in.readVInt();
if (compressedLength > compressed.length) {
compressed = new byte[ArrayUtil.oversize(compressedLength, 1)];
// pad with extra "dummy byte": see javadocs for using Inflater(true)
// we do it for compliance, but its unnecessary for years in zlib.
final int paddedLength = compressedLength + 1;
if (paddedLength > compressed.length) {
compressed = new byte[ArrayUtil.oversize(paddedLength, 1)];
}
in.readBytes(compressed, 0, compressedLength);
compressed[compressedLength] = 0; // explicitly set dummy byte to 0
decompressor.reset();
decompressor.setInput(compressed, 0, compressedLength);
// extra "dummy byte"
decompressor.setInput(compressed, 0, paddedLength);
bytes.offset = bytes.length = 0;
while (true) {
@ -242,7 +247,7 @@ public abstract class CompressionMode {
byte[] compressed;
DeflateCompressor(int level) {
compressor = new Deflater(level);
compressor = new Deflater(level, true);
compressed = new byte[64];
}