[llvm-branch-commits] [libcxx] [libc++][format][3/7] Improves std::format performance. (PR #101817)

Louis Dionne via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Aug 20 09:42:33 PDT 2024


================
@@ -452,9 +452,9 @@ format_to(_OutIt __out_it, wformat_string<_Args...> __fmt, _Args&&... __args) {
 // fires too eagerly, see http://llvm.org/PR61563.
 template <class = void>
 [[nodiscard]] _LIBCPP_ALWAYS_INLINE inline _LIBCPP_HIDE_FROM_ABI string vformat(string_view __fmt, format_args __args) {
-  string __res;
-  std::vformat_to(std::back_inserter(__res), __fmt, __args);
-  return __res;
+  __format::__allocating_buffer<char> __buffer;
----------------
ldionne wrote:

It would actually be really nice if `vformat_to(std::back_inserter(string), ...)` were just as performant as using the allocating buffer. It seems to me that if using the `__allocating_buffer` directly is faster, there may be a problem with next patch's `buffer_selector` which would basically be picking a less efficient approach for the case of `std::back_inserter<std::string>`.

https://github.com/llvm/llvm-project/pull/101817


More information about the llvm-branch-commits mailing list