From 7b25c857ded357c0cb0b481dac6404c27ed0293d Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Wed, 5 Jul 2017 15:15:42 +0200 Subject: Reduce stringstream creation/imbue overhead --- src/Utilities.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src/Utilities.cpp') diff --git a/src/Utilities.cpp b/src/Utilities.cpp index eb06d8b..eb34092 100644 --- a/src/Utilities.cpp +++ b/src/Utilities.cpp @@ -73,7 +73,24 @@ std::vector stringToFloatVector(const std::string &s) std::vector stringToDoubleVector(const std::string &s) { - return stringToVector(s); + std::vector out; + out.reserve(100); + std::istringstream iss; + iss.imbue(std::locale::classic()); + size_t current = 0; + size_t next; + do { + next = s.find_first_of(",;", current); + std::string t = s.substr(current, next - current); + iss.str(t); + iss.clear(); + double f; + iss >> f; + out.push_back(f); + current = next + 1; + } while (next != std::string::npos); + + return out; } template -- cgit v1.2.3