libstdc++: Reuse double overload of __convert_to_v if possible

Message ID 20230724200642.84915-1-jwakely@redhat.com
State Accepted
Headers
Series libstdc++: Reuse double overload of __convert_to_v if possible |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Jonathan Wakely July 24, 2023, 8:05 p.m. UTC
  This seems like a worthwhile change. In theory we could make it even
smaller by using a symbol alias, but I'm not sure that's supported on
the targets where this will actually help.

Any objections?

-- >8 --

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 | 6 ++++++
 1 file changed, 6 insertions(+)
  

Patch

diff --git a/libstdc++-v3/config/locale/generic/c_locale.cc b/libstdc++-v3/config/locale/generic/c_locale.cc
index 8849d78fdfa..866ba0361dc 100644
--- a/libstdc++-v3/config/locale/generic/c_locale.cc
+++ b/libstdc++-v3/config/locale/generic/c_locale.cc
@@ -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