From d2f64e95fdb0bc89b327325f2b7eeada03547499 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Sun, 30 Jan 2005 14:09:58 +0000 Subject: [PATCH] re PR libstdc++/19642 (streaming doubles is very slow compared to sprintf) 2005-01-30 Paolo Carlini PR libstdc++/19642 * config/locale/generic/c_locale.h (__convert_from_v): Switch only LC_NUMERIC, and only when actually != "C". From-SVN: r94440 --- libstdc++-v3/ChangeLog | 6 ++++++ libstdc++-v3/config/locale/generic/c_locale.h | 20 +++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index b41ead4d170..63349ec9587 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,9 @@ +2005-01-30 Paolo Carlini + + PR libstdc++/19642 + * config/locale/generic/c_locale.h (__convert_from_v): Switch only + LC_NUMERIC, and only when actually != "C". + 2005-01-28 Paolo Carlini * include/tr1/type_traits (is_function): Minor consistency tweaks. diff --git a/libstdc++-v3/config/locale/generic/c_locale.h b/libstdc++-v3/config/locale/generic/c_locale.h index a1a56868613..7b2282b04f6 100644 --- a/libstdc++-v3/config/locale/generic/c_locale.h +++ b/libstdc++-v3/config/locale/generic/c_locale.h @@ -59,18 +59,26 @@ namespace std const char* __fmt, _Tv __v, const __c_locale&, int __prec) { - char* __old = std::setlocale(LC_ALL, NULL); - char* __sav = new char[std::strlen(__old) + 1]; - std::strcpy(__sav, __old); - std::setlocale(LC_ALL, "C"); + char* __old = std::setlocale(LC_NUMERIC, NULL); + char* __sav = NULL; + if (std::strcmp(__old, "C")) + { + __sav = new char[std::strlen(__old) + 1]; + std::strcpy(__sav, __old); + std::setlocale(LC_NUMERIC, "C"); + } #ifdef _GLIBCXX_USE_C99 const int __ret = std::snprintf(__out, __size, __fmt, __prec, __v); #else const int __ret = std::sprintf(__out, __fmt, __prec, __v); #endif - std::setlocale(LC_ALL, __sav); - delete [] __sav; + + if (__sav) + { + std::setlocale(LC_NUMERIC, __sav); + delete [] __sav; + } return __ret; } } -- 2.30.2