[libcxx-commits] [PATCH] D112361: [libc++][format] Buffer changes proof-of-concept
Arthur O'Dwyer via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Oct 31 09:07:52 PDT 2021
Quuxplusone 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();
+ }
----------------
>>! @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?).
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