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