public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed] libstdc++: Reuse double overload of __convert_to_v if possible
Date: Thu, 17 Aug 2023 21:32:29 +0100	[thread overview]
Message-ID: <20230817203237.1131595-1-jwakely@redhat.com> (raw)

Tested x86_64-linux. Pushed to trunk.

-- >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(+)

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
-- 
2.41.0


             reply	other threads:[~2023-08-17 20:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-17 20:32 Jonathan Wakely [this message]
2023-08-17 23:19 ` Hans-Peter Nilsson
2023-08-17 23:30   ` Jonathan Wakely

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230817203237.1131595-1-jwakely@redhat.com \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).