zynaddsubfx

ZynAddSubFX open source synthesizer
Log | Files | Refs | Submodules | LICENSE

commit bce78598538276b4a38186189a5f0d03f5c48451
parent a0dcbd2d726e3744671cce64b99592b394f47087
Author: fundamental <[email protected]>
Date:   Mon, 28 Dec 2009 15:32:41 -0500

Samples: Optimization

- using memcpy and memset over for loops

Diffstat:
Msrc/Samples/Sample.cpp | 18+++++-------------
1 file changed, 5 insertions(+), 13 deletions(-)

diff --git a/src/Samples/Sample.cpp b/src/Samples/Sample.cpp @@ -35,8 +35,7 @@ Sample::Sample(const Sample &smp) :bufferSize(smp.bufferSize) { buffer = new REALTYPE[bufferSize]; - for(int i = 0; i < bufferSize; ++i) - *(i + buffer) = *(i + smp.buffer); + memcpy(buffer, smp.buffer, bufferSize * sizeof(float)); } Sample::Sample(int length, REALTYPE fill) @@ -45,8 +44,7 @@ Sample::Sample(int length, REALTYPE fill) if(length < 1) bufferSize = 1; buffer = new REALTYPE[bufferSize]; - for(int i = 0; i < bufferSize; ++i) - buffer[i] = fill; + memset(buffer, fill, bufferSize * sizeof(float)); } Sample::Sample(int length, const REALTYPE *input) @@ -54,8 +52,7 @@ Sample::Sample(int length, const REALTYPE *input) { if(length > 0) { buffer = new REALTYPE[length]; - for(int i = 0; i < length; ++i) - *(buffer + i) = *(input + i); + memcpy(buffer, input, bufferSize * sizeof(float)); } else { buffer = new REALTYPE[1]; @@ -77,17 +74,12 @@ void Sample::clear() void Sample::operator=(const Sample &smp) { - /**\todo rewrite to be less repetitive*/ - if(bufferSize == smp.bufferSize) - for(int i = 0; i < bufferSize; ++i) - *(i + buffer) = *(i + smp.buffer); - else { + if(bufferSize != smp.bufferSize) { delete[] buffer; buffer = new REALTYPE[smp.bufferSize]; bufferSize = smp.bufferSize; - for(int i = 0; i < bufferSize; ++i) - *(i + buffer) = *(i + smp.buffer); } + memcpy(buffer, smp.buffer, bufferSize * sizeof(float)); } bool Sample::operator==(const Sample &smp) const