This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Optimization for std::to_string()


Patch in attachments.

Tested on x86_64-linux-gnu.

Regards, niXman
C++ for Bitcoins:
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);
-      return _String(__s, __s + __len);
+      __str.resize(__len);
+      return __str;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]