[libcxx-commits] [PATCH] D59178: [libc++] Speedup to_string and to_wstring for integers using stack buffer and SSO

Marshall Clow via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Mar 12 15:46:22 PDT 2019


mclow.lists added inline comments.


================
Comment at: libcxx/src/string.cpp:358-359
+    typename S::value_type buf[size] = {};
+    const int len = sprintf_like(buf, size, fmt, a);
+    return S(buf, buf + len);
+}
----------------
ivafanas wrote:
> lebedev.ri wrote:
> > Missing error checking.
> > ```
> > RETURN VALUE
> >        Upon successful return, these functions return the number of characters printed (excluding the null byte used to end output to strings).
> > 
> > ```
> `size` is chosen in the way that there should be enough space for integer:
> `4 * sizeof(V)`: 2^8 = 256 - 3 digits + 1 digit for minus.
> 
> GCC implementation ignores negative return values so as they knows that space is enough:
> https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/ext/string_conversions.h#L99
> 
> In case of unexpected `sprintf` failure I will add fallback to the previous algorithm.
Because of licensing issues, we aren't able to refer to GCC's source code.
Please help us do so by not posting links, snippets, etc from GCC here.



Repository:
  rCXX libc++

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59178/new/

https://reviews.llvm.org/D59178





More information about the libcxx-commits mailing list