Skip to content

Commit

Permalink
file: Do not allocate write lz4 buffers in read mode
Browse files Browse the repository at this point in the history
  • Loading branch information
shramov committed Dec 19, 2024
1 parent 311cd61 commit 6f17eb2
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/channel/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,11 @@ class File : public tll::channel::AutoSeq<File<TIO>>

int _lz4_init(size_t block)
{
_lz4_buf.resize(LZ4_compressBound(block));
if (_lz4_encode.init(block))
return this->_log.fail(EINVAL, "Failed to init lz4 encoder with block size {}", block);
if (this->internal.caps & caps::Output) {
_lz4_buf.resize(LZ4_compressBound(block));
if (_lz4_encode.init(block))
return this->_log.fail(EINVAL, "Failed to init lz4 encoder with block size {}", block);
}
if (_lz4_decode.init(block))
return this->_log.fail(EINVAL, "Failed to init lz4 decoder with block size {}", block);
_lz4_decode_offset = -1;
Expand All @@ -117,7 +119,8 @@ class File : public tll::channel::AutoSeq<File<TIO>>

void _lz4_reset()
{
_lz4_encode.reset();
if (this->internal.caps & caps::Output)
_lz4_encode.reset();
_lz4_decode.reset();
_lz4_decode_offset = -1;
}
Expand Down

0 comments on commit 6f17eb2

Please sign in to comment.