speed up snprintf double to string by removing unused code but default to using karma for now given it is more future proof - followup to #1697
This commit is contained in:
parent
27554cbef8
commit
84197b1b98
1 changed files with 11 additions and 19 deletions
|
@ -35,17 +35,19 @@
|
||||||
boost::spirit::domain_::domain, name##_expr_type); \
|
boost::spirit::domain_::domain, name##_expr_type); \
|
||||||
BOOST_AUTO(name, boost::proto::deep_copy(expr)); \
|
BOOST_AUTO(name, boost::proto::deep_copy(expr)); \
|
||||||
|
|
||||||
//#define MAPNIK_KARMA_TO_STRING
|
// karma is used by default unless
|
||||||
|
// the boost version is too old
|
||||||
|
#define MAPNIK_KARMA_TO_STRING
|
||||||
|
|
||||||
#ifdef MAPNIK_KARMA_TO_STRING
|
#ifdef MAPNIK_KARMA_TO_STRING
|
||||||
#include <boost/version.hpp>
|
#include <boost/version.hpp>
|
||||||
#if BOOST_VERSION < 104500
|
#if BOOST_VERSION < 104500
|
||||||
#error you must have >= boost 104500 to use karma for string output
|
#undef MAPNIK_KARMA_TO_STRING
|
||||||
#endif
|
#else
|
||||||
|
#include <boost/spirit/include/karma.hpp>
|
||||||
#include <boost/spirit/include/karma.hpp>
|
#include <cmath> // log10
|
||||||
#include <cmath> // log10
|
#include <boost/math/special_functions/trunc.hpp> // trunc to avoid needing C++11
|
||||||
#include <boost/math/special_functions/trunc.hpp> // trunc to avoid needing C++11
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
@ -342,16 +344,6 @@ bool to_string(std::string & s, bool val)
|
||||||
|
|
||||||
bool to_string(std::string & s, double val)
|
bool to_string(std::string & s, double val)
|
||||||
{
|
{
|
||||||
double abs_n = std::fabs(val);
|
|
||||||
std::string format;
|
|
||||||
if (abs_n >= 1e16 || abs_n < 1e-4)
|
|
||||||
{
|
|
||||||
format = "%e";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
format = "%g";
|
|
||||||
}
|
|
||||||
s.resize(s.capacity());
|
s.resize(s.capacity());
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue