Use std::copy_n/std::fill_n instead of std::copy/std::fill where possible.
--- a/src/in_gsf/vbam/apu/Blip_Buffer.cpp
+++ b/src/in_gsf/vbam/apu/Blip_Buffer.cpp
@@ -264,7 +264,7 @@
fimpulse[blip_res + half_size + i] = fimpulse[blip_res + half_size - 1 - i];
// starts at 0
- std::fill(&fimpulse[0], &fimpulse[blip_res], 0.0f);
+ std::fill_n(&fimpulse[0], blip_res, 0.0f);
// find rescale factor
double total = std::accumulate(&fimpulse[blip_res], &fimpulse[blip_res + half_size], 0.0);
--- a/src/in_gsf/vbam/apu/Gb_Apu.cpp
+++ b/src/in_gsf/vbam/apu/Gb_Apu.cpp
@@ -83,7 +83,7 @@
void Gb_Apu::reset_regs()
{
- std::fill(&this->regs[0], &this->regs[0x20], 0);
+ std::fill_n(&this->regs[0], 0x20, 0);
this->square1.reset();
this->square2.reset();
--- a/src/in_gsf/vbam/gba/GBA.cpp
+++ b/src/in_gsf/vbam/gba/GBA.cpp
@@ -1505,7 +1505,7 @@
cpuBitsSet[i] = count;
}
- std::fill(&ioReadable[0], &ioReadable[0x304], true);
+ std::fill_n(&ioReadable[0], 0x304, true);
std::fill(&ioReadable[0x10], &ioReadable[0x48], false);
std::fill(&ioReadable[0x4c], &ioReadable[0x50], false);
std::fill(&ioReadable[0x54], &ioReadable[0x60], false);
--- a/src/in_ncsf/SSEQPlayer/Channel.h
+++ b/src/in_ncsf/SSEQPlayer/Channel.h
@@ -102,11 +102,11 @@
RingBuffer() : bufferPos(N / 2), getPos(N / 2)
{
- std::fill(&this->buffer[0], &this->buffer[N * 2], 0);
+ std::fill_n(&this->buffer[0], N * 2, 0);
}
void Clear()
{
- std::fill(&this->buffer[0], &this->buffer[N * 2], 0);
+ std::fill_n(&this->buffer[0], N * 2, 0);
this->bufferPos = this->getPos = N / 2;
}
void PushSample(int16_t sample)
@@ -125,11 +125,11 @@
if (this->bufferPos + size > N * 3 / 2)
{
size_t free = N * 3 / 2 - this->bufferPos;
- std::copy(&samples[0], &samples[free], &this->buffer[this->bufferPos]);
+ std::copy_n(&samples[0], free, &this->buffer[this->bufferPos]);
std::copy(&samples[free], &samples[size], &this->buffer[N / 2]);
}
else
- std::copy(&samples[0], &samples[size], &this->buffer[this->bufferPos]);
+ std::copy_n(&samples[0], size, &this->buffer[this->bufferPos]);
size_t rightFree = this->bufferPos < N ? N - this->bufferPos : 0;
if (rightFree < size)
{
@@ -137,18 +137,18 @@
{
size_t leftStart = this->bufferPos - N;
size_t leftSize = std::min(N / 2 - leftStart, size);
- std::copy(&samples[0], &samples[leftSize], &this->buffer[leftStart]);
+ std::copy_n(&samples[0], leftSize, &this->buffer[leftStart]);
if (leftSize < size)
std::copy(&samples[leftSize], &samples[size], &this->buffer[N * 3 / 2]);
}
else
{
- std::copy(&samples[0], &samples[rightFree], &this->buffer[this->bufferPos + N]);
+ std::copy_n(&samples[0], rightFree, &this->buffer[this->bufferPos + N]);
std::copy(&samples[rightFree], &samples[size], &this->buffer[0]);
}
}
else
- std::copy(&samples[0], &samples[size], &this->buffer[this->bufferPos + N]);
+ std::copy_n(&samples[0], size, &this->buffer[this->bufferPos + N]);
this->bufferPos += size;
if (this->bufferPos >= N * 3 / 2)
this->bufferPos -= N;
--- a/src/in_xsf_framework/XSFPlayer.cpp
+++ b/src/in_xsf_framework/XSFPlayer.cpp
@@ -66,12 +66,12 @@
if (this->uses32BitSamplesClampedTo16Bit)
{
auto trueBufLong = reinterpret_cast<int32_t *>(&trueBuffer[0]);
- std::copy(&trueBufLong[0], &trueBufLong[bufsize << 1], &bufLong[0]);
+ std::copy_n(&trueBufLong[0], bufsize << 1, &bufLong[0]);
}
else
{
auto trueBufShort = reinterpret_cast<int16_t *>(&trueBuffer[0]);
- std::copy(&trueBufShort[0], &trueBufShort[bufsize << 1], &bufLong[0]);
+ std::copy_n(&trueBufShort[0], bufsize << 1, &bufLong[0]);
}
if (detectSilence || skipSilenceOnStartSec)
{
@@ -117,7 +117,7 @@
{
auto tmpBuf = std::vector<int32_t>((bufsize - skipOffset) << 1);
std::copy(&bufLong[(offset + skipOffset) << 1], &bufLong[bufsize << 1], &tmpBuf[0]);
- std::copy(&tmpBuf[0], &tmpBuf[(bufsize - skipOffset) << 1], &bufLong[offset << 1]);
+ std::copy_n(&tmpBuf[0], (bufsize - skipOffset) << 1, &bufLong[offset << 1]);
pos += skipOffset;
}
else
@@ -131,12 +131,12 @@
if (this->uses32BitSamplesClampedTo16Bit)
{
auto trueBufLong = reinterpret_cast<int32_t *>(&trueBuffer[0]);
- std::copy(&bufLong[0], &bufLong[bufsize << 1], &trueBufLong[0]);
+ std::copy_n(&bufLong[0], bufsize << 1, &trueBufLong[0]);
}
else
{
auto trueBufShort = reinterpret_cast<int16_t *>(&trueBuffer[0]);
- std::copy(&bufLong[0], &bufLong[bufsize << 1], &trueBufShort[0]);
+ std::copy_n(&bufLong[0], bufsize << 1, &trueBufShort[0]);
}
}
}
@@ -188,7 +188,7 @@
else
{
auto trueBufShort = reinterpret_cast<int16_t *>(&trueBuffer[0]);
- std::copy(&bufLong[0], &bufLong[bufsize << 1], &trueBufShort[0]);
+ std::copy_n(&bufLong[0], bufsize << 1, &trueBufShort[0]);
std::copy(&trueBuffer[0], &trueBuffer[bufsize << 2], &buf[0]);
}