1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +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,6 +487,23 @@ public:
jassert (dataToReferTo != nullptr); jassert (dataToReferTo != nullptr);
jassert (newNumChannels >= 0 && newNumSamples >= 0); jassert (newNumChannels >= 0 && newNumSamples >= 0);
size = newNumSamples;
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) if (allocatedBytes != 0)
{ {
allocatedBytes = 0; allocatedBytes = 0;
@ -494,9 +511,9 @@ public:
} }
numChannels = newNumChannels; numChannels = newNumChannels;
size = newNumSamples;
allocateChannels (dataToReferTo, newStartSample); allocateChannels (dataToReferTo, newStartSample);
}
jassert (! isClear); jassert (! isClear);
} }