This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Optimization for std::to_string()
- From: niXman <i dot nixman at autistici dot org>
- To: gcc-patches at gcc dot gnu dot org, libstdc++ at gcc dot gnu dot org
- Date: Fri, 20 Jul 2018 12:44:27 +0300
- Subject: Optimization for std::to_string()
Hi,
Patch in attachments.
Tested on x86_64-linux-gnu.
--
Regards, niXman
___________________________________________________
C++ for Bitcoins: github.com/niXman
Index: libstdc++-v3/include/ext/string_conversions.h
===================================================================
--- libstdc++-v3/include/ext/string_conversions.h (revision 262879)
+++ libstdc++-v3/include/ext/string_conversions.h (working copy)
@@ -100,19 +100,18 @@
__builtin_va_list), std::size_t __n,
const _CharT* __fmt, ...)
{
- // XXX Eventually the result should be constructed in-place in
- // the __cxx11 string, likely with the help of internal hooks.
- _CharT* __s = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
- * __n));
+ _String __str(__n, 0);
__builtin_va_list __args;
__builtin_va_start(__args, __fmt);
- const int __len = __convf(__s, __n, __fmt, __args);
+ const std::size_t __len = __convf(&__str[0], __n, __fmt, __args);
__builtin_va_end(__args);
- return _String(__s, __s + __len);
+ __str.resize(__len);
+
+ return __str;
}
_GLIBCXX_END_NAMESPACE_VERSION