refactor xml parser, uses faster string to double conversion

This commit is contained in:
Dennis Luxen
2014-04-29 15:33:13 +02:00
parent b7704f0c7f
commit a1ecab2f95
3 changed files with 318 additions and 229 deletions
+34
View File
@@ -126,6 +126,40 @@ static inline uint64_t stringToInt64(const std::string& input) {
return value;
}
// source: http://tinodidriksen.com/2011/05/28/cpp-convert-string-to-double-speed/
static inline double StringToDouble(const char *p)
{
double r = 0.0;
bool neg = false;
if (*p == '-')
{
neg = true;
++p;
}
while (*p >= '0' && *p <= '9')
{
r = (r*10.0) + (*p - '0');
++p;
}
if (*p == '.')
{
double f = 0.0;
int n = 0;
++p;
while (*p >= '0' && *p <= '9')
{
f = (f*10.0) + (*p - '0');
++p;
++n;
}
r += f / std::pow(10.0, n);
}
if (neg)
{
r = -r;
}
return r;
}
static inline void doubleToString(const double value, std::string & output){
output.clear();