From 29c5f32d4287a49f59fcd65b7ffacd7f154b03aa Mon Sep 17 00:00:00 2001 From: Niels Date: Mon, 29 Aug 2016 22:36:33 +0200 Subject: [PATCH] fixed performance degradation (#272) --- Makefile | 3 +++ src/json.hpp | 3 ++- src/json.hpp.re2c | 3 ++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index b53d8d3dc..4c96bad7f 100644 --- a/Makefile +++ b/Makefile @@ -66,6 +66,9 @@ fuzz: test/src/fuzz.cpp src/json.hpp cppcheck: cppcheck --enable=warning --inconclusive --force --std=c++11 src/json.hpp --error-exitcode=1 +clang_sanitize: clean + CXX=clang++ CXXFLAGS="-g -O2 -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer" $(MAKE) + ########################################################################## # maintainer targets ########################################################################## diff --git a/src/json.hpp b/src/json.hpp index b5e24206b..d6f8925fc 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -2232,7 +2232,8 @@ class basic_json { std::stringstream ss; // fix locale problems - ss.imbue(std::locale(std::locale(), new DecimalSeparator)); + const static std::locale loc(std::locale(), new DecimalSeparator); + ss.imbue(loc); // 6, 15 or 16 digits of precision allows round-trip IEEE 754 // string->float->string, string->double->string or string->long diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index fdc006387..75fc27e5a 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -2232,7 +2232,8 @@ class basic_json { std::stringstream ss; // fix locale problems - ss.imbue(std::locale(std::locale(), new DecimalSeparator)); + const static std::locale loc(std::locale(), new DecimalSeparator); + ss.imbue(loc); // 6, 15 or 16 digits of precision allows round-trip IEEE 754 // string->float->string, string->double->string or string->long