[*] optimize the other half (aa7f783f
) of compression streams when used with the interceptor interface
This commit is contained in:
parent
519ba4b26e
commit
90e08d534c
@ -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)
|
||||
{
|
||||
|
||||
|
@ -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"
|
@ -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)))
|
||||
{
|
||||
|
@ -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"
|
||||
}
|
@ -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");
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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_)
|
||||
{
|
||||
|
@ -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_)
|
||||
{
|
||||
|
@ -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_)
|
||||
{
|
||||
|
@ -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_)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user