aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2024-04-29 18:16:29 +0100
committerJonathan Wakely <redi@gcc.gnu.org>2024-09-14 13:46:30 +0100
commit99b8be43d7c548db127ee4f4d0918c55edc68b3f (patch)
tree73d0f7fc4c0033c4247ef47067569dcc5b5f2061
parent01670a4095791733e0389acead832e3da757c9d7 (diff)
downloadgcc-99b8be43d7c548db127ee4f4d0918c55edc68b3f.zip
gcc-99b8be43d7c548db127ee4f4d0918c55edc68b3f.tar.gz
gcc-99b8be43d7c548db127ee4f4d0918c55edc68b3f.tar.bz2
libstdc++: Tweak localized formatting for floating-point types
libstdc++-v3/ChangeLog: * include/std/format (__formatter_fp::_M_localize): Add comments and micro-optimize string copy.
-rw-r--r--libstdc++-v3/include/std/format17
1 files changed, 10 insertions, 7 deletions
diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format
index 52243eb..e963d7f 100644
--- a/libstdc++-v3/include/std/format
+++ b/libstdc++-v3/include/std/format
@@ -1886,25 +1886,28 @@ namespace __format
if (__grp.empty() && __point == __dot)
return __lstr; // Locale uses '.' and no grouping.
- size_t __d = __str.find(__dot);
- size_t __e = min(__d, __str.find(__exp));
+ size_t __d = __str.find(__dot); // Index of radix character (if any).
+ size_t __e = min(__d, __str.find(__exp)); // First of radix or exponent
if (__e == __str.npos)
__e = __str.size();
- const size_t __r = __str.size() - __e;
+ const size_t __r = __str.size() - __e; // Length of remainder.
auto __overwrite = [&](_CharT* __p, size_t) {
+ // Apply grouping to the digits before the radix or exponent.
auto __end = std::__add_grouping(__p, __np.thousands_sep(),
__grp.data(), __grp.size(),
__str.data(), __str.data() + __e);
- if (__r)
+ if (__r) // If there's a fractional part or exponent
{
if (__d != __str.npos)
{
- *__end = __point;
+ *__end = __point; // Add the locale's radix character.
++__end;
++__e;
}
- if (__r > 1)
- __end += __str.copy(__end, __str.npos, __e);
+ const size_t __rlen = __str.size() - __e;
+ // Append fractional digits and/or exponent:
+ char_traits<_CharT>::copy(__end, __str.data() + __e, __rlen);
+ __end += __rlen;
}
return (__end - __p);
};