[*] optimize the other half (aa7f783f) of compression streams when used with the interceptor interface

This commit is contained in:
Reece Wilson 2023-06-10 20:03:29 +01:00
parent 519ba4b26e
commit 90e08d534c
15 changed files with 54 additions and 17 deletions

View File

@ -8,6 +8,8 @@
#include <Source/RuntimeInternal.hpp>
#include "AuCompression.hpp"
#include "AuIngestableReadBase.hpp"
#include "AuBaseStream.hpp" // now required for *.inl
#include "AuIngestableReadBase.inl"
#include "AuBaseStream.hpp"
namespace Aurora::Compression
@ -122,6 +124,16 @@ namespace Aurora::Compression
}
}
AuSPtr<Memory::ByteBuffer> BaseStream::GetWeakBuffer()
{
return AuTryLockMemoryType(this->wpInBuffer_);
}
void BaseStream::SetWeakBuffer(const AuSPtr<Memory::ByteBuffer> &pBuffer)
{
this->wpInBuffer_ = pBuffer;
}
void BaseStream::InitByDesc(CompressInfo &info)
{

View File

@ -47,6 +47,9 @@ namespace Aurora::Compression
AuSPtr<Memory::ByteBuffer> GetBuffer();
void SetBuffer(const AuSPtr<Memory::ByteBuffer> &pBuffer);
AuSPtr<Memory::ByteBuffer> GetWeakBuffer();
void SetWeakBuffer(const AuSPtr<Memory::ByteBuffer> &pBuffer);
void InitByDesc(CompressInfo &info);
void InitByDesc(DecompressInfo &info);
@ -54,10 +57,13 @@ namespace Aurora::Compression
virtual AuStreamReadWrittenPair_t Ingest_s(AuUInt32 dwBytesFromUnprocessedInputSource) = 0;
AuSPtr<Memory::ByteBuffer> pOutputBuffer_;
AuWPtr<Memory::ByteBuffer> wpInBuffer_;
AuSPtr<AuIO::IStreamWriter> pOutputBufferInterface_;
AuSPtr<Memory::ByteBuffer> pFallbackTempBuffer_;
Memory::ByteBuffer _outbufferOwned;
AuThreadPrimitives::SpinLock _spinlock;
AuUInt32 uBufferSize_;
};
}
}
#include "AuIngestableReadBase.inl"

View File

@ -56,17 +56,20 @@ namespace Aurora::Compression
const AuSPtr<Memory::ByteBuffer> &pWriteOutByteBuffer)
{
this->pLastBuffer_ = pReadInByteBuffer;
this->pBaseStream_->SetWeakBuffer(pReadInByteBuffer);
this->pBaseStream_->SetBuffer(pWriteOutByteBuffer);
if (this->LimitHasHit())
{
if (!this->bPassthrough_)
{
this->pBaseStream_->SetWeakBuffer({});
return true;
}
auto uCount = pWriteOutByteBuffer->WriteFromEx(*pReadInByteBuffer, AuNumericLimits<AuUInt>::max());
pReadInByteBuffer->readPtr += uCount;
this->pBaseStream_->SetWeakBuffer({});
return bool(uCount);
}
@ -83,7 +86,9 @@ namespace Aurora::Compression
bSuccess = a != 0;
}
while (bSuccess);
this->pBaseStream_->SetWeakBuffer({});
if ((this->bAutoFlush_) ||
(AuExchange(this->bSendFlush_, false)))
{

View File

@ -21,14 +21,13 @@ namespace Aurora::Compression
inline void SetPointer(void *pointer, AuUInt32 dwLength);
template<typename T, typename Z>
inline AuUInt32 IngestForInPointer(const AuSPtr<IO::IStreamReader> &reader, T *&in, Z &inAlreadyAvailable, AuUInt32 dwAmount);
inline AuUInt32 IngestForInPointer(const AuSPtr<IO::IStreamReader> &reader, T *&in, Z &inAlreadyAvailable, AuUInt32 dwAmount, struct BaseStream *pThat);
protected:
AuUInt8 *internalInBuffer_ {};
AuUInt32 internalInLength_ {};
AuUInt8 *internalOutBuffer_ {};
AuUInt32 internalOutLength_ {};
bool bIsSpecialNotZlibLike {};
};
}
#include "AuIngestableReadBase.inl"
}

View File

@ -27,6 +27,7 @@ namespace Aurora::Compression
{
this->internalInBuffer_ = AuReinterpretCast<AuUInt8 *>(pHead);
this->internalInLength_ = dwLength;
this->bIsSpecialNotZlibLike = true;
}
// Given a zlib-like interface input paremeters, a stream source, and a buffer...
@ -36,8 +37,22 @@ namespace Aurora::Compression
AuUInt32 IngestableReadBase::IngestForInPointer(const AuSPtr<IO::IStreamReader> &reader,
T *&in,
Z &inAlreadyAvailable,
AuUInt32 dwAmount)
AuUInt32 dwAmount,
BaseStream *pThat)
{
if (!this->bIsSpecialNotZlibLike)
{
if (auto pBuffer = pThat->GetWeakBuffer())
{
auto view = pBuffer->GetLinearReadable(dwAmount);
in = (T *)view.ptr;
inAlreadyAvailable = view.length;
pBuffer->readPtr += view.length;
return view.length;
}
}
if (inAlreadyAvailable > this->internalInLength_)
{
SysPanic("Invalid Buffer Position");

View File

@ -79,7 +79,7 @@ namespace Aurora::Compression
while (read < input)
{
read += IngestForInPointer<char, uInt>(this->pReader_, this->ctx_.next_in, this->ctx_.avail_in, input - read);
read += IngestForInPointer<char, uInt>(this->pReader_, this->ctx_.next_in, this->ctx_.avail_in, input - read, this);
if (!this->ctx_.avail_in)
{

View File

@ -82,7 +82,7 @@ namespace Aurora::Compression
{
auto [pMainDOut, uMainDOutLength] = this->GetDOutPair();
read += IngestForInPointer<char, uInt>(this->pReader_, this->ctx_.next_in, this->ctx_.avail_in, input - read);
read += IngestForInPointer<char, uInt>(this->pReader_, this->ctx_.next_in, this->ctx_.avail_in, input - read, this);
if (!this->ctx_.avail_in)
{

View File

@ -65,7 +65,7 @@ namespace Aurora::Compression
while (read < input)
{
read += IngestForInPointer<uint8_t, size_t>(this->pReader_, this->pInBuffer, this->uAvailIn, input - read);
read += IngestForInPointer<uint8_t, size_t>(this->pReader_, this->pInBuffer, this->uAvailIn, input - read, this);
if (!this->uAvailIn)
{

View File

@ -60,7 +60,7 @@ namespace Aurora::Compression
while (read < input)
{
read += IngestForInPointer<uint8_t, size_t>(this->pReader_, this->pInBuffer, this->uAvailIn, input - read);
read += IngestForInPointer<uint8_t, size_t>(this->pReader_, this->pInBuffer, this->uAvailIn, input - read, this);
if (!this->uAvailIn)
{

View File

@ -63,7 +63,7 @@ namespace Aurora::Compression
while (read < input)
{
read += IngestForInPointer<Bytef, uInt>(this->pReader_, this->ctx_.next_in, this->ctx_.avail_in, input - read);
read += IngestForInPointer<Bytef, uInt>(this->pReader_, this->ctx_.next_in, this->ctx_.avail_in, input - read, this);
if (!this->ctx_.avail_in)
{

View File

@ -69,7 +69,7 @@ namespace Aurora::Compression
while (read < input)
{
read += IngestForInPointer<Bytef, uInt>(this->pReader_, this->ctx_.next_in, this->ctx_.avail_in, input - read);
read += IngestForInPointer<Bytef, uInt>(this->pReader_, this->ctx_.next_in, this->ctx_.avail_in, input - read, this);
if (!this->ctx_.avail_in)
{

View File

@ -165,7 +165,7 @@ namespace Aurora::Compression
while (inputStat < input)
{
inputStat += IngestForInPointer<char, uInt>(this->pReader_, this->pReadPtr_, this->uBufferInAvail_, input - inputStat);
inputStat += IngestForInPointer<char, uInt>(this->pReader_, this->pReadPtr_, this->uBufferInAvail_, input - inputStat, this);
if (!this->uBufferInAvail_)
{

View File

@ -74,7 +74,7 @@ namespace Aurora::Compression
while (inputStat < input)
{
inputStat += IngestForInPointer<char, uInt>(this->pReader_, this->pReadPtr_, this->uBufferInAvail_, input - inputStat);
inputStat += IngestForInPointer<char, uInt>(this->pReader_, this->pReadPtr_, this->uBufferInAvail_, input - inputStat, this);
if (!this->uBufferInAvail_)
{

View File

@ -85,7 +85,7 @@ namespace Aurora::Compression
while (read < input)
{
read += IngestForInPointer<char, AuUInt32>(this->pReader_, this->pIterator_, this->uAvailableIn_, input - read);
read += IngestForInPointer<char, AuUInt32>(this->pReader_, this->pIterator_, this->uAvailableIn_, input - read, this);
if (!this->uAvailableIn_)
{

View File

@ -64,7 +64,7 @@ namespace Aurora::Compression
while (read < input)
{
read += IngestForInPointer<char, AuUInt32>(this->pReader_, this->pIterator_, this->uAvailableIn_, input - read);
read += IngestForInPointer<char, AuUInt32>(this->pReader_, this->pIterator_, this->uAvailableIn_, input - read, this);
if (!this->uAvailableIn_)
{