From 0f5155bcde9703b7ebc50ac70c953ae9a0832b02 Mon Sep 17 00:00:00 2001 From: rimathia Date: Thu, 12 Nov 2020 15:52:39 +0100 Subject: [PATCH 1/4] detail::write in one more place relevant to printf with long arguments, requires moving the definition of detail::write up in the file --- include/fmt/format.h | 59 ++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index b18303b022c5..08a019146b95 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -638,6 +638,7 @@ void iterator_buffer::flush() { out_ = copy_str(data_, data_ + this->limit(this->size()), out_); this->clear(); } + } // namespace detail // The number of characters to store in the basic_memory_buffer object itself @@ -1518,6 +1519,34 @@ FMT_NOINLINE OutputIt fill(OutputIt it, size_t n, const fill_t& fill) { return it; } +template +OutputIt write(OutputIt out, monostate) { + FMT_ASSERT(false, ""); + return out; +} + +template ::value)> +OutputIt write(OutputIt out, string_view value) { + auto it = reserve(out, value.size()); + it = copy_str(value.begin(), value.end(), it); + return base_iterator(out, it); +} + +template +OutputIt write(OutputIt out, basic_string_view value) { + auto it = reserve(out, value.size()); + it = copy_str(value.begin(), value.end(), it); + return base_iterator(out, it); +} + +template +buffer_appender write(buffer_appender out, + basic_string_view value) { + get_container(out).append(value.begin(), value.end()); + return out; +} + // Writes the output of f, padded according to format specifications in specs. // size: output size in code units. // width: output display width in (terminal) column positions. @@ -1607,7 +1636,7 @@ OutputIt write(OutputIt out, basic_string_view s, : 0; using iterator = remove_reference_t; return write_padded(out, specs, size, width, [=](iterator it) { - return copy_str(data, data + size, it); + return detail::write(it, basic_string_view(data, size)); }); } @@ -2034,34 +2063,6 @@ template struct is_integral : std::is_integral {}; template <> struct is_integral : std::true_type {}; template <> struct is_integral : std::true_type {}; -template -OutputIt write(OutputIt out, monostate) { - FMT_ASSERT(false, ""); - return out; -} - -template ::value)> -OutputIt write(OutputIt out, string_view value) { - auto it = reserve(out, value.size()); - it = copy_str(value.begin(), value.end(), it); - return base_iterator(out, it); -} - -template -OutputIt write(OutputIt out, basic_string_view value) { - auto it = reserve(out, value.size()); - it = copy_str(value.begin(), value.end(), it); - return base_iterator(out, it); -} - -template -buffer_appender write(buffer_appender out, - basic_string_view value) { - get_container(out).append(value.begin(), value.end()); - return out; -} - template ::value && !std::is_same::value && From 960f5bdb82703db2463ee915b21cc13d7e158f2d Mon Sep 17 00:00:00 2001 From: rimathia Date: Thu, 12 Nov 2020 18:19:43 +0100 Subject: [PATCH 2/4] remove whitespace change --- include/fmt/format.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 08a019146b95..e04d43384e7c 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -638,7 +638,6 @@ void iterator_buffer::flush() { out_ = copy_str(data_, data_ + this->limit(this->size()), out_); this->clear(); } - } // namespace detail // The number of characters to store in the basic_memory_buffer object itself From 6684314ccd2b48b32f5884b43d1ddd9133bb755d Mon Sep 17 00:00:00 2001 From: rimathia Date: Fri, 13 Nov 2020 20:38:57 +0100 Subject: [PATCH 3/4] add specialization of copy_str instead of using detail::write in it --- include/fmt/format.h | 66 +++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index e04d43384e7c..4e461f7d1e7e 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -605,6 +605,14 @@ OutputIt copy_str(InputIt begin, InputIt end, OutputIt it) { return it; } +template ::value)> +buffer_appender copy_str(InputIt begin, InputIt end, + buffer_appender out) { + get_container(out).append(begin, end); + return out; +} + template inline counting_iterator copy_str(InputIt begin, InputIt end, counting_iterator it) { @@ -1518,34 +1526,6 @@ FMT_NOINLINE OutputIt fill(OutputIt it, size_t n, const fill_t& fill) { return it; } -template -OutputIt write(OutputIt out, monostate) { - FMT_ASSERT(false, ""); - return out; -} - -template ::value)> -OutputIt write(OutputIt out, string_view value) { - auto it = reserve(out, value.size()); - it = copy_str(value.begin(), value.end(), it); - return base_iterator(out, it); -} - -template -OutputIt write(OutputIt out, basic_string_view value) { - auto it = reserve(out, value.size()); - it = copy_str(value.begin(), value.end(), it); - return base_iterator(out, it); -} - -template -buffer_appender write(buffer_appender out, - basic_string_view value) { - get_container(out).append(value.begin(), value.end()); - return out; -} - // Writes the output of f, padded according to format specifications in specs. // size: output size in code units. // width: output display width in (terminal) column positions. @@ -1635,7 +1615,7 @@ OutputIt write(OutputIt out, basic_string_view s, : 0; using iterator = remove_reference_t; return write_padded(out, specs, size, width, [=](iterator it) { - return detail::write(it, basic_string_view(data, size)); + return copy_str(data, data + size, it); }); } @@ -2062,6 +2042,34 @@ template struct is_integral : std::is_integral {}; template <> struct is_integral : std::true_type {}; template <> struct is_integral : std::true_type {}; +template +OutputIt write(OutputIt out, monostate) { + FMT_ASSERT(false, ""); + return out; +} + +template ::value)> +OutputIt write(OutputIt out, string_view value) { + auto it = reserve(out, value.size()); + it = copy_str(value.begin(), value.end(), it); + return base_iterator(out, it); +} + +template +OutputIt write(OutputIt out, basic_string_view value) { + auto it = reserve(out, value.size()); + it = copy_str(value.begin(), value.end(), it); + return base_iterator(out, it); +} + +template +buffer_appender write(buffer_appender out, + basic_string_view value) { + get_container(out).append(value.begin(), value.end()); + return out; +} + template ::value && !std::is_same::value && From 7ed5c6942cdb3c010ec4ebf9b8d8631f6f4961ba Mon Sep 17 00:00:00 2001 From: rimathia Date: Fri, 13 Nov 2020 21:03:05 +0100 Subject: [PATCH 4/4] remove now unnecessary overload --- include/fmt/format.h | 7 ------- 1 file changed, 7 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 4e461f7d1e7e..b8b64a30f02c 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -2063,13 +2063,6 @@ OutputIt write(OutputIt out, basic_string_view value) { return base_iterator(out, it); } -template -buffer_appender write(buffer_appender out, - basic_string_view value) { - get_container(out).append(value.begin(), value.end()); - return out; -} - template ::value && !std::is_same::value &&