[*] Redo ByteBuffer::Pad for write streams
This commit is contained in:
parent
a1c1e88f51
commit
588322252f
@ -19,23 +19,26 @@ namespace Aurora::Memory
|
||||
return Resize(this->length - tail);
|
||||
}
|
||||
|
||||
bool ByteBuffer::Fill(AuUInt length, AuUInt8 magicCharacter)
|
||||
bool ByteBuffer::Fill(AuUInt uLength, AuUInt8 magicCharacter)
|
||||
{
|
||||
ByteBufferPushWriteState a(*this);
|
||||
|
||||
auto maxLinear = this->writePtr - AuMin(this->readPtr, this->base + this->length);
|
||||
maxLinear = AuMin(AuUInt(maxLinear), length);
|
||||
|
||||
if (maxLinear)
|
||||
AuUInt32 uLinear {};
|
||||
if (auto view = this->GetNextLinearWrite())
|
||||
{
|
||||
AuMemset(this->writePtr, magicCharacter, maxLinear);
|
||||
this->writePtr += maxLinear;
|
||||
uLinear = view.ToLength();
|
||||
AuMemset(view.Begin(), magicCharacter, uLinear);
|
||||
this->writePtr += uLinear;
|
||||
}
|
||||
|
||||
if (maxLinear != length)
|
||||
if (uLinear != uLength)
|
||||
{
|
||||
auto delta = length - maxLinear;
|
||||
auto delta = uLength - uLinear;
|
||||
|
||||
AuArray<AuUInt8, 32> tempA;
|
||||
|
||||
if (delta > 32)
|
||||
{
|
||||
// HACK:
|
||||
Memory::ByteBuffer inner(delta);
|
||||
if (!inner)
|
||||
@ -50,6 +53,16 @@ namespace Aurora::Memory
|
||||
return {};
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AuMemset(tempA.data(), magicCharacter, 32);
|
||||
|
||||
if (!Write(tempA.data(), delta))
|
||||
{
|
||||
return {};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -58,22 +71,21 @@ namespace Aurora::Memory
|
||||
{
|
||||
ByteBufferPushWriteState a(*this);
|
||||
|
||||
auto oldLen = this->length;
|
||||
auto newLen = ((this->length + aPowOf2) & ~(aPowOf2 - 1));
|
||||
auto oldLen = this->writePtr - this->base;
|
||||
auto length = this->flagCircular ? this->RemainingBytes() : oldLen;
|
||||
auto newLen = AuPageRoundUp<AuUInt>(length, aPowOf2);
|
||||
|
||||
if (!Resize(newLen))
|
||||
{
|
||||
return {};
|
||||
return false;
|
||||
}
|
||||
|
||||
auto old = this->writePtr - this->base;
|
||||
this->writePtr = this->base + oldLen;
|
||||
if (!this->Fill(newLen - oldLen))
|
||||
if (!this->Fill(newLen - oldLen, magicCharacter))
|
||||
{
|
||||
return {};
|
||||
return false;
|
||||
}
|
||||
|
||||
this->writePtr = this->base + old;
|
||||
this->writePtr = this->base + length;
|
||||
return true;
|
||||
}
|
||||
}
|
@ -268,7 +268,22 @@ namespace Aurora::Memory
|
||||
return this->length;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
AuUInt Length() const
|
||||
{
|
||||
return this->length;
|
||||
}
|
||||
|
||||
AuUInt ToSize() const
|
||||
{
|
||||
return this->length;
|
||||
}
|
||||
|
||||
AuUInt Size() const
|
||||
{
|
||||
return this->length;
|
||||
}
|
||||
|
||||
template<typename T = AuUInt8>
|
||||
AuUInt ToCount() const
|
||||
{
|
||||
return this->length / sizeof(T);
|
||||
|
Loading…
Reference in New Issue
Block a user