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:
parent
848082095f
commit
bc3c171c9d
1 changed files with 25 additions and 8 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue