audiovisualwaveform: optimize shifting code
This commit is contained in:
@@ -184,9 +184,7 @@ void AudioVisualWaveform::Shift(const rational &from, const rational &to)
|
|||||||
// Shifting backwards <-
|
// Shifting backwards <-
|
||||||
int copy_sz = data.size() - from_index;
|
int copy_sz = data.size() - from_index;
|
||||||
|
|
||||||
for (int i=0; i<copy_sz; i++) {
|
memcpy(&data.data()[to_index], &data.data()[from_index], copy_sz * sizeof(SamplePerChannel));
|
||||||
data.replace(to_index + i, data.at(from_index + i));
|
|
||||||
}
|
|
||||||
|
|
||||||
data.resize(data.size() - (from_index - to_index));
|
data.resize(data.size() - (from_index - to_index));
|
||||||
} else {
|
} else {
|
||||||
@@ -199,9 +197,10 @@ void AudioVisualWaveform::Shift(const rational &from, const rational &to)
|
|||||||
|
|
||||||
int copy_sz = old_sz - from_index;
|
int copy_sz = old_sz - from_index;
|
||||||
|
|
||||||
for (int i=0; i<copy_sz; i++) {
|
// Copy to a temporary buffer first to prevent overwriting bytes we need to copy
|
||||||
data.replace(data.size() - i - 1, data.at(old_sz - i - 1));
|
QByteArray temp(copy_sz * sizeof(SamplePerChannel), Qt::Uninitialized);
|
||||||
}
|
memcpy(temp.data(), &data.data()[from_index], temp.size());
|
||||||
|
memcpy(&data.data()[to_index], temp.data(), temp.size());
|
||||||
|
|
||||||
memset(reinterpret_cast<char*>(&data[from_index]), 0, distance * sizeof(SamplePerChannel));
|
memset(reinterpret_cast<char*>(&data[from_index]), 0, distance * sizeof(SamplePerChannel));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user