1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

MemoryOutputStream: Avoid allocating unnecessarily large buffers

Previously, we would allocate storage large enough to fit the entire
contents of the input stream, even if this was lower than the
maxNumBytesToWrite.
This commit is contained in:
reuk 2022-12-08 18:58:43 +00:00
parent 76adebee13
commit 84d4c8794a
No known key found for this signature in database
GPG key ID: 9ADCD339CFC98A11

View file

@ -176,11 +176,11 @@ int64 MemoryOutputStream::writeFromInputStream (InputStream& source, int64 maxNu
if (availableData > 0)
{
if (maxNumBytesToWrite > availableData || maxNumBytesToWrite < 0)
if (maxNumBytesToWrite < 0 || availableData < maxNumBytesToWrite)
maxNumBytesToWrite = availableData;
if (blockToUse != nullptr)
preallocate (position + (size_t) availableData);
preallocate (position + (size_t) maxNumBytesToWrite);
}
return OutputStream::writeFromInputStream (source, maxNumBytesToWrite);