]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Reuse double overload of __convert_to_v if possible
authorJonathan Wakely <jwakely@redhat.com>
Mon, 24 Jul 2023 10:38:32 +0000 (11:38 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 17 Aug 2023 19:24:19 +0000 (20:24 +0100)
For targets where double and long double have the same representation we
can reuse the same __convert_to_v code for both types. This will
slightly reduce the size of the compiled code in the library.

libstdc++-v3/ChangeLog:

* config/locale/generic/c_locale.cc (__convert_to_v): Reuse
double overload for long double if possible.

libstdc++-v3/config/locale/generic/c_locale.cc

index 8849d78fdfac7057230ecadc1a76f2117a2ef6b7..866ba0361dc4b8c86b27bb5b504995de85c11e02 100644 (file)
@@ -187,6 +187,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     __convert_to_v(const char* __s, long double& __v,
                   ios_base::iostate& __err, const __c_locale&) throw()
     {
+#if __DBL_MANT_DIG__ == __LDBL_MANT_DIG__
+      double __d;
+      __convert_to_v(__s, __d, __err, __c_locale);
+      __v = __d;
+#else
       // Assumes __s formatted for "C" locale.
       const char* __sav = __set_C_locale();
       if (!__sav)
@@ -233,6 +238,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
       setlocale(LC_ALL, __sav);
       delete [] __sav;
+#endif // __DBL_MANT_DIG__ == __LDBL_MANT_DIG__
     }
 
   void