[libcxx-commits] [PATCH] D112361: [libc++][format] Buffer changes proof-of-concept
Mark de Wever via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Nov 2 11:01:07 PDT 2021
Mordante added inline comments.
================
Comment at: libcxx/include/__format/buffer.h:79-85
+ _LIBCPP_HIDE_FROM_ABI void put(_CharT __c) {
+ *__buffer_it_++ = __c;
+ // Profiling showed flushing after adding is more efficient than flushing
+ // when entering the function.
+ if (__buffer_it_ == __buffer_.end())
+ flush();
+ }
----------------
Quuxplusone wrote:
> >>! @vitaut wrote on D110495:
> > I think D112361 is a step in the right direction. You can do even better and make it represent a contiguous (not necessarily fixed-size) buffer with a single type-erased reallocation/flush function. Then it can be used to write to contiguous containers like vector and string which is a common case directly avoiding copies. This is basically what {fmt} does.
>
> Charlie Barto also showed MSVC STL doing that approach, in his CppCon talk on Thursday. https://cppcon.digital-medium.co.uk/thursday-recordings/
> IIRC, basically they have `_Size, _Capacity, virtual void _Grow()`; and whenever `_Size == _Capacity` they call `_Grow`. I guess I remain fuzzy on the details of what `_Grow` would actually do for a `std::string` (does it resize? does it merely reserve?).
That looks a lot like what fmt does. I tested with a similar approach, but the virtual call seems to have a measurable impact over the `__fun_(__buffer_.begin(), __buffer_it_, __obj_);` method.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D112361/new/
https://reviews.llvm.org/D112361
More information about the libcxx-commits
mailing list