[libcxx-commits] [PATCH] D110495: [libc++][format][2/6] Adds a __output_iterator.

Mark de Wever via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sun Sep 26 05:49:17 PDT 2021


Mordante created this revision.
Mordante added reviewers: ldionne, vitaut.
Herald added a subscriber: mgorny.
Mordante requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

Instead of using a temporary `string` in `__vformat_to_wrapped` use a new
generic iterator. This aids to reduce the number of template instantions
and avoids using a `string` to buffer the entire formatted output.

This changes the type of `format_context` and `wformat_context`, this can
still be done since the code isn't ABI stable yet.

Several approaches have been evaluated:

- Using a __output_buffer base class with:
  - a put function to store the buffer in its internal buffer
  - a virtual flush function to copy the internal buffer to the output
- Using a `function` to forward the output operation to the output buffer, much like the next method.
- Using a type erased function point to store the data in the buffer.

The last version resulted in the best performance. For some cases there's
still a loss of speed over the original method. This loss many becomes
apparent when large strings are copied to a pointer like iterator, before
the compiler optimized this using `memcpy`.

Depends on D110494 <https://reviews.llvm.org/D110494>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110495

Files:
  libcxx/include/CMakeLists.txt
  libcxx/include/__format/buffer.h
  libcxx/include/__format/format_context.h
  libcxx/include/format
  libcxx/include/module.modulemap
  libcxx/test/libcxx/diagnostics/detail.headers/format/buffer.module.verify.cpp
  libcxx/test/libcxx/utilities/format/format.formatter/format.context/types.compile.pass.cpp
  libcxx/test/std/utilities/format/format.formatter/format.context/types.compile.pass.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110495.375092.patch
Type: text/x-patch
Size: 10774 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210926/1fa1be96/attachment.bin>


More information about the libcxx-commits mailing list