separate explicit finalization for buffers

This commit is contained in:
Yakov Olkhovskiy 2024-01-16 22:15:35 +00:00
parent 73f1ed3b69
commit 92d42567fa
8 changed files with 13 additions and 64 deletions

View File

@ -43,13 +43,6 @@ public:
return offset();
}
protected:
void finalizeImpl() override
{
BufferWithOwnMemory<WriteBuffer>::finalizeImpl();
out.finalize();
}
private:
void nextImpl() override;

View File

@ -23,17 +23,7 @@ BrotliWriteBuffer::BrotliStateWrapper::~BrotliStateWrapper()
BrotliEncoderDestroyInstance(state);
}
BrotliWriteBuffer::~BrotliWriteBuffer()
{
try
{
finalize();
}
catch (...)
{
tryLogCurrentException(__PRETTY_FUNCTION__);
}
}
BrotliWriteBuffer::~BrotliWriteBuffer() = default;
void BrotliWriteBuffer::nextImpl()
{

View File

@ -33,17 +33,7 @@ Bzip2WriteBuffer::Bzip2StateWrapper::~Bzip2StateWrapper()
BZ2_bzCompressEnd(&stream);
}
Bzip2WriteBuffer::~Bzip2WriteBuffer()
{
try
{
finalize();
}
catch (...)
{
tryLogCurrentException(__PRETTY_FUNCTION__);
}
}
Bzip2WriteBuffer::~Bzip2WriteBuffer() = default;
void Bzip2WriteBuffer::nextImpl()
{

View File

@ -44,14 +44,8 @@ void LZMADeflatingWriteBuffer::initialize(int compression_level)
LZMADeflatingWriteBuffer::~LZMADeflatingWriteBuffer()
{
try
{
finalize();
}
catch (...)
{
tryLogCurrentException(__PRETTY_FUNCTION__);
}
/// It is OK to call deflateEnd() twice (one from the finalizeAfter())
lzma_end(&lstr);
}
void LZMADeflatingWriteBuffer::nextImpl()

View File

@ -91,14 +91,8 @@ void Lz4DeflatingWriteBuffer::initialize(int compression_level)
Lz4DeflatingWriteBuffer::~Lz4DeflatingWriteBuffer()
{
try
{
finalize();
}
catch (...)
{
tryLogCurrentException(__PRETTY_FUNCTION__);
}
if (ctx)
LZ4F_freeCompressionContext(ctx);
}
void Lz4DeflatingWriteBuffer::nextImpl()

View File

@ -44,14 +44,8 @@ void ZlibDeflatingWriteBuffer::nextImpl()
ZlibDeflatingWriteBuffer::~ZlibDeflatingWriteBuffer()
{
try
{
finalize();
}
catch (...)
{
tryLogCurrentException(__PRETTY_FUNCTION__);
}
/// It is OK to call deflateEnd() twice (one from the finalizeAfter() that does the proper error checking)
deflateEnd(&zstr);
}
void ZlibDeflatingWriteBuffer::finalizeBefore()

View File

@ -51,14 +51,8 @@ void ZstdDeflatingWriteBuffer::initialize(int compression_level, int window_log)
ZstdDeflatingWriteBuffer::~ZstdDeflatingWriteBuffer()
{
try
{
finalize();
}
catch (...)
{
tryLogCurrentException(__PRETTY_FUNCTION__);
}
if (cctx)
ZSTD_freeCCtx(cctx);
}
void ZstdDeflatingWriteBuffer::flush(ZSTD_EndDirective mode)

View File

@ -87,9 +87,9 @@ private:
return;
finalized = true;
if (out_maybe_compressed)
out_maybe_compressed->finalize();
else if (out)
if (out_compressed_holder)
out_compressed_holder->finalize();
if (out)
out->finalize();
}