aboutsummaryrefslogtreecommitdiff
path: root/libcxx/include/__format
diff options
context:
space:
mode:
authorMark de Wever <koraq@xs4all.nl>2023-04-21 08:09:06 +0200
committerMark de Wever <koraq@xs4all.nl>2023-07-18 20:07:11 +0200
commit3f65f718332c96c7ececcd9cde84be740076a4f1 (patch)
tree22b322df2ba07e679758bbdac2e994019f4af342 /libcxx/include/__format
parentb88db47bd2085c2c8a246751feb63a3ac20a3665 (diff)
downloadllvm-3f65f718332c96c7ececcd9cde84be740076a4f1.zip
llvm-3f65f718332c96c7ececcd9cde84be740076a4f1.tar.gz
llvm-3f65f718332c96c7ececcd9cde84be740076a4f1.tar.bz2
[libc++][print] Adds FILE functions.
Drive-by fix to make sure the __retarget_buffer works correctly whan using a hint of 1. This was discovered in one of the new tests. Drive-by fixes __retarget_buffer when initialized with size 1. Implements parts of - P2093R14 Formatted output - P2539R4 Should the output of std::print to a terminal be synchronized with the underlying stream? Reviewed By: #libc, ldionne Differential Revision: https://reviews.llvm.org/D150044
Diffstat (limited to 'libcxx/include/__format')
-rw-r--r--libcxx/include/__format/buffer.h10
1 files changed, 9 insertions, 1 deletions
diff --git a/libcxx/include/__format/buffer.h b/libcxx/include/__format/buffer.h
index f43fd13..45f9da8 100644
--- a/libcxx/include/__format/buffer.h
+++ b/libcxx/include/__format/buffer.h
@@ -529,6 +529,7 @@ public:
struct __iterator {
using difference_type = ptrdiff_t;
+ using value_type = _CharT;
_LIBCPP_HIDE_FROM_ABI constexpr explicit __iterator(__retarget_buffer& __buffer)
: __buffer_(std::addressof(__buffer)) {}
@@ -551,7 +552,14 @@ public:
__retarget_buffer& operator=(const __retarget_buffer&) = delete;
_LIBCPP_HIDE_FROM_ABI explicit __retarget_buffer(size_t __size_hint) {
- auto __result = std::__allocate_at_least(__alloc_, __size_hint ? __size_hint : 256 / sizeof(_CharT));
+ // When the initial size is very small a lot of resizes happen
+ // when elements added. So use a hard-coded minimum size.
+ //
+ // Note a size < 2 will not work
+ // - 0 there is no buffer, while push_back requires 1 empty element.
+ // - 1 multiplied by the grow factor is 1 and thus the buffer never
+ // grows.
+ auto __result = std::__allocate_at_least(__alloc_, std::max(__size_hint, 256 / sizeof(_CharT)));
__ptr_ = __result.ptr;
__capacity_ = __result.count;
}