1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-09 23:34:20 +00:00

AudioBuffer: Avoid unnecessary allocations when reassigning referenced channels

This commit is contained in:
reuk 2025-09-04 14:22:18 +01:00
parent 848082095f
commit bc3c171c9d
No known key found for this signature in database

View file

@ -487,16 +487,33 @@ public:
jassert (dataToReferTo != nullptr);
jassert (newNumChannels >= 0 && newNumSamples >= 0);
if (allocatedBytes != 0)
{
allocatedBytes = 0;
allocatedData.free();
}
numChannels = newNumChannels;
size = newNumSamples;
allocateChannels (dataToReferTo, newStartSample);
if (newNumChannels <= numChannels)
{
numChannels = newNumChannels;
std::transform (dataToReferTo, dataToReferTo + numChannels, channels, [&] (auto* src)
{
jassert (src != nullptr);
return src + newStartSample;
});
channels[numChannels] = nullptr;
isClear = false;
}
else
{
if (allocatedBytes != 0)
{
allocatedBytes = 0;
allocatedData.free();
}
numChannels = newNumChannels;
allocateChannels (dataToReferTo, newStartSample);
}
jassert (! isClear);
}