Reduce ArrayUtil#grow in decompress (#12996)

This commit is contained in:
Zhang Chao 2024-02-26 04:09:48 +08:00 committed by GitHub
parent 47021ae98f
commit ca06693a16
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 1 deletions

View File

@ -198,6 +198,8 @@ Improvements
Optimizations
---------------------
* GITHUB#12996: Reduce ArrayUtil#grow in decompress. (Zhang Chao)
* GITHUB#13115: Short circuit queued flush check when flush on update is disabled (Prabhat Sharma)
* GITHUB#13085: Remove unnecessary toString() / substring() calls to save some String allocations (Dmitry Cherniachenko)

View File

@ -128,10 +128,12 @@ public final class LZ4WithPresetDictCompressionMode extends CompressionMode {
}
// Read blocks that intersect with the interval we need
if (offsetInBlock < offset + length) {
bytes.bytes = ArrayUtil.grow(bytes.bytes, bytes.length + offset + length - offsetInBlock);
}
while (offsetInBlock < offset + length) {
final int bytesToDecompress = Math.min(blockLength, offset + length - offsetInBlock);
LZ4.decompress(in, bytesToDecompress, buffer, dictLength);
bytes.bytes = ArrayUtil.grow(bytes.bytes, bytes.length + bytesToDecompress);
System.arraycopy(buffer, dictLength, bytes.bytes, bytes.length, bytesToDecompress);
bytes.length += bytesToDecompress;
offsetInBlock += blockLength;