From 05eaab78163dd53bfebbc0af298d50397c01faa8 Mon Sep 17 00:00:00 2001 From: dehnert Date: Tue, 27 Nov 2012 22:07:28 +0100 Subject: [PATCH] Removed invocations of memcpy in favour of std::copy as compilers will take care of optimizations. --- src/models/GraphTransitions.h | 6 +++--- src/storage/BitVector.h | 5 ++--- src/storage/SquareSparseMatrix.h | 7 ++++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/models/GraphTransitions.h b/src/models/GraphTransitions.h index 88ef44f7f..af9709669 100644 --- a/src/models/GraphTransitions.h +++ b/src/models/GraphTransitions.h @@ -10,7 +10,7 @@ #include "src/storage/SquareSparseMatrix.h" -#include +#include namespace mrmc { @@ -92,7 +92,7 @@ private: // First, we copy the index list from the sparse matrix as this will // stay the same. - memcpy(this->stateIndications, transitionMatrix->getRowIndicationsPointer(), numberOfStates + 1); + std::copy(transitionMatrix->getRowIndicationsPointer(), transitionMatrix->getRowIndicationsPointer() + numberOfStates + 1, this->stateIndications); // Now we can iterate over all rows of the transition matrix and record // the target state. @@ -134,7 +134,7 @@ private: // Create an array that stores the next index for each state. Initially // this corresponds to the previously computed accumulated offsets. uint_fast64_t* nextIndicesList = new uint_fast64_t[numberOfStates]; - memcpy(nextIndicesList, stateIndications, numberOfStates * sizeof(uint_fast64_t)); + std::copy(stateIndications, stateIndications + numberOfStates, nextIndicesList); // Now we are ready to actually fill in the list of predecessors for // every state. Again, we start by considering all but the last row. diff --git a/src/storage/BitVector.h b/src/storage/BitVector.h index b8f21a916..6c94b7504 100644 --- a/src/storage/BitVector.h +++ b/src/storage/BitVector.h @@ -10,7 +10,6 @@ #include "src/exceptions/invalid_argument.h" #include "src/exceptions/out_of_range.h" -#include #include "log4cplus/logger.h" #include "log4cplus/loggingmacros.h" @@ -142,7 +141,7 @@ public: BitVector(const BitVector &bv) : bucketCount(bv.bucketCount) { LOG4CPLUS_WARN(logger, "Invoking copy constructor."); bucketArray = new uint_fast64_t[bucketCount]; - memcpy(bucketArray, bv.bucketArray, sizeof(uint_fast64_t) * bucketCount); + std::copy(bv.bucketArray, bv.bucketArray + bucketCount, bucketArray); } //! Destructor @@ -170,7 +169,7 @@ public: // Copy over the elements from the old bit vector. uint_fast64_t copySize = (newBucketCount <= bucketCount) ? newBucketCount : bucketCount; - memcpy(tempArray, bucketArray, sizeof(uint_fast64_t) * copySize); + std::copy(bucketArray, bucketArray + copySize, tempArray); // Initialize missing values in the new bit vector. for (uint_fast64_t i = copySize; i < bucketCount; ++i) { diff --git a/src/storage/SquareSparseMatrix.h b/src/storage/SquareSparseMatrix.h index d2c2480bf..732dd2432 100644 --- a/src/storage/SquareSparseMatrix.h +++ b/src/storage/SquareSparseMatrix.h @@ -3,6 +3,7 @@ #include #include +#include #include "boost/integer/integer_mask.hpp" #include "src/exceptions/invalid_state.h" @@ -96,9 +97,9 @@ public: } // The elements that are not of the value type but rather the - // index type may be copied with memcpy. - memcpy(columnIndications, ssm.columnIndications, sizeof(columnIndications[0]) * nonZeroEntryCount); - memcpy(rowIndications, ssm.rowIndications, sizeof(rowIndications[0]) * (rowCount + 1)); + // index type may be copied directly. + std::copy(ssm.columnIndications, ssm.columnIndications + nonZeroEntryCount, columnIndications); + std::copy(ssm.rowIndications, ssm.rowIndications + rowCount + 1, rowIndications); } } }