|
|
|
@@ -68,13 +68,18 @@ void MemoryOutputStream::reset() noexcept |
|
|
|
size = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryOutputStream::prepareToWrite (size_t numBytes)
|
|
|
|
char* MemoryOutputStream::prepareToWrite (size_t numBytes)
|
|
|
|
{
|
|
|
|
jassert ((ssize_t) numBytes >= 0);
|
|
|
|
size_t storageNeeded = position + numBytes;
|
|
|
|
|
|
|
|
if (storageNeeded >= data.getSize())
|
|
|
|
data.ensureSize ((storageNeeded + jmin (storageNeeded / 2, (size_t) (1024 * 1024)) + 32) & ~31u);
|
|
|
|
|
|
|
|
char* const writePointer = static_cast <char*> (data.getData()) + position;
|
|
|
|
position += numBytes;
|
|
|
|
size = jmax (size, position);
|
|
|
|
return writePointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MemoryOutputStream::write (const void* const buffer, size_t howMany)
|
|
|
|
@@ -82,12 +87,7 @@ bool MemoryOutputStream::write (const void* const buffer, size_t howMany) |
|
|
|
jassert (buffer != nullptr && ((ssize_t) howMany) >= 0);
|
|
|
|
|
|
|
|
if (howMany > 0)
|
|
|
|
{
|
|
|
|
prepareToWrite (howMany);
|
|
|
|
memcpy (static_cast<char*> (data.getData()) + position, buffer, howMany);
|
|
|
|
position += howMany;
|
|
|
|
size = jmax (size, position);
|
|
|
|
}
|
|
|
|
memcpy (prepareToWrite (howMany), buffer, howMany);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
@@ -95,12 +95,12 @@ bool MemoryOutputStream::write (const void* const buffer, size_t howMany) |
|
|
|
void MemoryOutputStream::writeRepeatedByte (uint8 byte, size_t howMany)
|
|
|
|
{
|
|
|
|
if (howMany > 0)
|
|
|
|
{
|
|
|
|
prepareToWrite (howMany);
|
|
|
|
memset (static_cast<char*> (data.getData()) + position, byte, howMany);
|
|
|
|
position += howMany;
|
|
|
|
size = jmax (size, position);
|
|
|
|
}
|
|
|
|
memset (prepareToWrite (howMany), byte, howMany);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryOutputStream::appendUTF8Char (juce_wchar c)
|
|
|
|
{
|
|
|
|
CharPointer_UTF8 (prepareToWrite (CharPointer_UTF8::getBytesRequiredFor (c))).write (c);
|
|
|
|
}
|
|
|
|
|
|
|
|
MemoryBlock MemoryOutputStream::getMemoryBlock() const
|
|
|
|
|