From cbaefb32dad6d0ad8e6d6e34874ccae183cf6a56 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Mon, 16 Dec 2013 20:36:48 +0000 Subject: [PATCH] speed optimization --- src/buffer.h | 27 +++++++++++++++++---------- src/util.h | 1 + 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/buffer.h b/src/buffer.h index da7e0e75..002f1986 100755 --- a/src/buffer.h +++ b/src/buffer.h @@ -204,11 +204,13 @@ public: else { // data can be written in one step - const int iEnd = iPutPos + iInSize; - while ( iPutPos < iEnd ) - { - vecMemory[iPutPos++] = vecData[iCurPos++]; - } + std::copy ( vecData.begin(), + vecData.begin() + iInSize, + vecMemory.begin() + iPutPos ); + + // set the put position one block further (no wrap around needs + // to be considered here) + iPutPos += iInSize; } } @@ -269,11 +271,16 @@ public: else { // data can be read in one step - const int iEnd = iGetPos + iInSize; - while ( iGetPos < iEnd ) - { - vecData[iCurPos++] = vecMemory[iGetPos++]; - } + const std::vector::const_iterator ItMemoryGetPos = + vecMemory.begin() + iGetPos; + + std::copy ( ItMemoryGetPos, + ItMemoryGetPos + iInSize, + vecData.begin() ); + + // set the get position one block further (no wrap around needs + // to be considered here) + iGetPos += iInSize; } } diff --git a/src/util.h b/src/util.h index 57ca7cfb..cd1c9eae 100755 --- a/src/util.h +++ b/src/util.h @@ -37,6 +37,7 @@ #include #include #include +#include #include "global.h" using namespace std; // because of the library: "vector" #ifdef _WIN32