summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWillem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl>2017-07-05 15:15:42 +0200
committerWillem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl>2017-10-17 20:35:30 +0200
commit7b25c857ded357c0cb0b481dac6404c27ed0293d (patch)
tree2b2d61cedfbfd0536a61fcda388030d41c36d57a
parent207e8f099f8004de82ee02fff235e85638ca2223 (diff)
downloadastra-7b25c857ded357c0cb0b481dac6404c27ed0293d.tar.gz
astra-7b25c857ded357c0cb0b481dac6404c27ed0293d.tar.bz2
astra-7b25c857ded357c0cb0b481dac6404c27ed0293d.tar.xz
astra-7b25c857ded357c0cb0b481dac6404c27ed0293d.zip
Reduce stringstream creation/imbue overhead
-rw-r--r--src/Utilities.cpp19
-rw-r--r--src/XMLNode.cpp17
2 files changed, 29 insertions, 7 deletions
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<float> stringToFloatVector(const std::string &s)
std::vector<double> stringToDoubleVector(const std::string &s)
{
- return stringToVector<double>(s);
+ std::vector<double> 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<typename T>
diff --git a/src/XMLNode.cpp b/src/XMLNode.cpp
index 3b7237f..0ddc511 100644
--- a/src/XMLNode.cpp
+++ b/src/XMLNode.cpp
@@ -30,6 +30,9 @@ along with the ASTRA Toolbox. If not, see <http://www.gnu.org/licenses/>.
#include "rapidxml/rapidxml.hpp"
#include "rapidxml/rapidxml_print.hpp"
+#include <sstream>
+#include <iomanip>
+
using namespace rapidxml;
using namespace astra;
@@ -399,8 +402,6 @@ void XMLNode::setContent(double* pfList, int _iSize)
template<typename T>
static std::string setContentMatrix_internal(T* _pfMatrix, int _iWidth, int _iHeight, bool transposed)
{
- std::string str = "";
-
int s1,s2;
if (!transposed) {
@@ -411,17 +412,21 @@ static std::string setContentMatrix_internal(T* _pfMatrix, int _iWidth, int _iHe
s2 = 1;
}
+ std::ostringstream s;
+ s.imbue(std::locale::classic());
+ s << std::setprecision(17);
+
for (int y = 0; y < _iHeight; ++y) {
if (_iWidth > 0)
- str += StringUtil::toString(_pfMatrix[0*s1 + y*s2]);
+ s << _pfMatrix[0*s1 + y*s2];
for (int x = 1; x < _iWidth; x++)
- str += "," + StringUtil::toString(_pfMatrix[x*s1 + y*s2]);
+ s << "," << _pfMatrix[x*s1 + y*s2];
if (y != _iHeight-1)
- str += ";";
+ s << ";";
}
- return str;
+ return s.str();
}
void XMLNode::setContent(float32* _pfMatrix, int _iWidth, int _iHeight, bool transposed)