[all-commits] [llvm/llvm-project] 555214: [libc++][format][2/6] Adds a __output_iterator.

mordante via All-commits all-commits at lists.llvm.org
Sat Mar 26 08:48:14 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 555214cbcc79eac401482e1a302f726b54182546
      https://github.com/llvm/llvm-project/commit/555214cbcc79eac401482e1a302f726b54182546
  Author: Mark de Wever <koraq at xs4all.nl>
  Date:   2022-03-26 (Sat, 26 Mar 2022)

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

  Log Message:
  -----------
  [libc++][format][2/6] Adds a __output_iterator.

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`.

Reviewed By: ldionne, vitaut, #libc

Differential Revision: https://reviews.llvm.org/D110495




More information about the All-commits mailing list