From 989e5b7798adc1da5f78225d8bc8ce53692af21e Mon Sep 17 00:00:00 2001 From: Nolan Check Date: Tue, 28 Jul 2009 07:40:18 +0000 Subject: [PATCH] Decent C++ for MathFloatVectorSum. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@3895 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Common/Src/MathUtil.cpp | 10 +++------- Source/Core/Common/Src/MathUtil.h | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/Source/Core/Common/Src/MathUtil.cpp b/Source/Core/Common/Src/MathUtil.cpp index 0a967e9a3f..6a8e1bbd8c 100644 --- a/Source/Core/Common/Src/MathUtil.cpp +++ b/Source/Core/Common/Src/MathUtil.cpp @@ -19,6 +19,7 @@ #include "MathUtil.h" #include +#include namespace { @@ -160,14 +161,9 @@ inline void MatrixMul(int n, const float *a, const float *b, float *result) } // Calculate sum of a float list -float MathFloatVectorSum(std::vector Vec) +float MathFloatVectorSum(const std::vector& Vec) { - float Sum = 0.0; - for(unsigned i = 0; i < Vec.size(); i++) - { - Sum += Vec.at(i); - } - return Sum; + return std::accumulate(Vec.begin(), Vec.end(), 0.0f); } void Matrix33::LoadIdentity(Matrix33 &mtx) diff --git a/Source/Core/Common/Src/MathUtil.h b/Source/Core/Common/Src/MathUtil.h index 6709cf1cc6..76fbcf3972 100644 --- a/Source/Core/Common/Src/MathUtil.h +++ b/Source/Core/Common/Src/MathUtil.h @@ -151,7 +151,7 @@ inline double pow2(double x) {return x * x;} void SaveSSEState(); void LoadSSEState(); void LoadDefaultSSEState(); -float MathFloatVectorSum(std::vector); +float MathFloatVectorSum(const std::vector&); #define ROUND_UP(x, a) (((x) + (a) - 1) & ~((a) - 1))