Skip to content

Commit e5eb963

Browse files
committed
Remove redundant zeroing
std::vector::resize already zeroes the new samples, so we don't need to use std::fill. See https://stackoverflow.com/a/73333009/10477326 However, we pass a second parameter to explicitly copy-init with zero and to not default-init.
1 parent 3d899f5 commit e5eb963

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

AudioFile.h

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -433,15 +433,9 @@ void AudioFile<T>::setAudioBufferSize (int numChannels, int numSamples)
433433
template <class T>
434434
void AudioFile<T>::setNumSamplesPerChannel (int numSamples)
435435
{
436-
int originalSize = getNumSamplesPerChannel();
437-
438436
for (int i = 0; i < getNumChannels();i++)
439437
{
440-
samples[i].resize (numSamples);
441-
442-
// set any new samples to zero
443-
if (numSamples > originalSize)
444-
std::fill (samples[i].begin() + originalSize, samples[i].end(), (T)0.);
438+
samples[i].resize (numSamples, static_cast<T>(0));
445439
}
446440
}
447441

@@ -456,13 +450,9 @@ void AudioFile<T>::setNumChannels (int numChannels)
456450

457451
// make sure any new channels are set to the right size
458452
// and filled with zeros
459-
if (numChannels > originalNumChannels)
453+
for (int i = originalNumChannels; i < numChannels; i++)
460454
{
461-
for (int i = originalNumChannels; i < numChannels; i++)
462-
{
463-
samples[i].resize (originalNumSamplesPerChannel);
464-
std::fill (samples[i].begin(), samples[i].end(), (T)0.);
465-
}
455+
samples[i].resize (originalNumSamplesPerChannel, static_cast<T>(0));
466456
}
467457
}
468458

0 commit comments

Comments
 (0)