This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[v3] Simplify __convert_from_v


Hi,

an obvious simplification, worth roughly 1% of performance in my
simple formatting tests.

Tested x86-linux, gnu/generic locale models.

Paolo.

//////////////
2004-08-07  Paolo Carlini  <pcarlini@suse.de>

	* config/locale/generic/c_locale.h (__convert_from_v): Don't
	use a default for __prec, assume __prec >= 0 and simplify.
	* config/locale/gnu/c_locale.h (__convert_from_v): Likewise.
	* include/bits/locale_facets.tcc (money_put<>::do_put(long double)):
	Pass format "%.*Lf" + precision == 0, equivalent to "%.0Lf".
diff -urN libstdc++-v3-orig/config/locale/generic/c_locale.h libstdc++-v3/config/locale/generic/c_locale.h
--- libstdc++-v3-orig/config/locale/generic/c_locale.h	2004-01-30 04:42:59.000000000 +0100
+++ libstdc++-v3/config/locale/generic/c_locale.h	2004-08-07 12:37:15.000000000 +0200
@@ -57,24 +57,17 @@
     __convert_from_v(char* __out, 
 		     const int __size __attribute__((__unused__)),
 		     const char* __fmt,
-		     _Tv __v, const __c_locale&, int __prec = -1)
+		     _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");
 
-      int __ret;
 #ifdef _GLIBCXX_USE_C99
-      if (__prec >= 0)
-        __ret = std::snprintf(__out, __size, __fmt, __prec, __v);
-      else
-        __ret = std::snprintf(__out, __size, __fmt, __v);
+      const int __ret = std::snprintf(__out, __size, __fmt, __prec, __v);
 #else
-      if (__prec >= 0)
-        __ret = std::sprintf(__out, __fmt, __prec, __v);
-      else
-        __ret = std::sprintf(__out, __fmt, __v);
+      const int __ret = std::sprintf(__out, __fmt, __prec, __v);
 #endif
       std::setlocale(LC_ALL, __sav);
       delete [] __sav;
diff -urN libstdc++-v3-orig/config/locale/gnu/c_locale.h libstdc++-v3/config/locale/gnu/c_locale.h
--- libstdc++-v3-orig/config/locale/gnu/c_locale.h	2004-01-30 04:42:59.000000000 +0100
+++ libstdc++-v3/config/locale/gnu/c_locale.h	2004-08-07 12:32:17.000000000 +0200
@@ -68,11 +68,11 @@
     int
     __convert_from_v(char* __out, const int __size, const char* __fmt,
 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
-		     _Tv __v, const __c_locale& __cloc, int __prec = -1)
+		     _Tv __v, const __c_locale& __cloc, int __prec)
     {
       __c_locale __old = __gnu_cxx::__uselocale(__cloc);
 #else
-		     _Tv __v, const __c_locale&, int __prec = -1)
+		     _Tv __v, const __c_locale&, int __prec)
     {
       char* __old = std::setlocale(LC_ALL, NULL);
       char* __sav = new char[std::strlen(__old) + 1];
@@ -80,17 +80,10 @@
       std::setlocale(LC_ALL, "C");
 #endif
 
-      int __ret;
 #ifdef _GLIBCXX_USE_C99
-      if (__prec >= 0)
-        __ret = std::snprintf(__out, __size, __fmt, __prec, __v);
-      else
-        __ret = std::snprintf(__out, __size, __fmt, __v);
+      const int __ret = std::snprintf(__out, __size, __fmt, __prec, __v);
 #else
-      if (__prec >= 0)
-        __ret = std::sprintf(__out, __fmt, __prec, __v);
-      else
-        __ret = std::sprintf(__out, __fmt, __v);
+      const int __ret = std::sprintf(__out, __fmt, __prec, __v);
 #endif
 
 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
diff -urN libstdc++-v3-orig/include/bits/locale_facets.tcc libstdc++-v3/include/bits/locale_facets.tcc
--- libstdc++-v3-orig/include/bits/locale_facets.tcc	2004-07-30 16:25:18.000000000 +0200
+++ libstdc++-v3/include/bits/locale_facets.tcc	2004-08-07 12:29:45.000000000 +0200
@@ -1689,22 +1689,22 @@
       char* __cs = static_cast<char*>(__builtin_alloca(__cs_size));
       // _GLIBCXX_RESOLVE_LIB_DEFECTS
       // 328. Bad sprintf format modifier in money_put<>::do_put()
-      int __len = std::__convert_from_v(__cs, __cs_size, "%.0Lf", __units,
-					_S_get_c_locale());
+      int __len = std::__convert_from_v(__cs, __cs_size, "%.*Lf", __units,
+					_S_get_c_locale(), 0);
       // If the buffer was not large enough, try again with the correct size.
       if (__len >= __cs_size)
 	{
 	  __cs_size = __len + 1;
 	  __cs = static_cast<char*>(__builtin_alloca(__cs_size));
-	  __len = std::__convert_from_v(__cs, __cs_size, "%.0Lf", __units,
-					_S_get_c_locale());
+	  __len = std::__convert_from_v(__cs, __cs_size, "%.*Lf", __units,
+					_S_get_c_locale(), 0);
 	}
 #else
       // max_exponent10 + 1 for the integer part, + 2 for sign and '\0'.
       const int __cs_size = numeric_limits<long double>::max_exponent10 + 3;
       char* __cs = static_cast<char*>(__builtin_alloca(__cs_size));
-      int __len = std::__convert_from_v(__cs, 0, "%.0Lf", __units,
-					_S_get_c_locale());
+      int __len = std::__convert_from_v(__cs, 0, "%.*Lf", __units,
+					_S_get_c_locale(), 0);
 #endif
       _CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
 							   * __cs_size));

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]