mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-24 12:14:26 +00:00
Optimize writing to buffers via back_insert_iterator
This commit is contained in:
parent
e2f6d7665b
commit
192859c2b5
@ -427,7 +427,7 @@ auto write(OutputIt out, const std::tm& time, const std::locale& loc,
|
||||
char format, char modifier = 0) -> OutputIt {
|
||||
auto&& buf = get_buffer<Char>(out);
|
||||
do_write<Char>(buf, time, loc, format, modifier);
|
||||
return get_iterator(buf);
|
||||
return get_iterator(buf, out);
|
||||
}
|
||||
|
||||
template <typename Char, typename OutputIt,
|
||||
|
@ -566,7 +566,7 @@ OutputIt vformat_to(
|
||||
basic_format_args<buffer_context<type_identity_t<Char>>> args) {
|
||||
auto&& buf = detail::get_buffer<Char>(out);
|
||||
detail::vformat_to(buf, ts, format_str, args);
|
||||
return detail::get_iterator(buf);
|
||||
return detail::get_iterator(buf, out);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1123,13 +1123,19 @@ template <typename T, typename OutputIt>
|
||||
auto get_buffer(OutputIt out) -> iterator_buffer<OutputIt, T> {
|
||||
return iterator_buffer<OutputIt, T>(out);
|
||||
}
|
||||
template <typename T, typename Buf,
|
||||
FMT_ENABLE_IF(std::is_base_of<buffer<char>, Buf>::value)>
|
||||
auto get_buffer(std::back_insert_iterator<Buf> out) -> buffer<char>& {
|
||||
return get_container(out);
|
||||
}
|
||||
|
||||
template <typename Buffer>
|
||||
FMT_INLINE auto get_iterator(Buffer& buf) -> decltype(buf.out()) {
|
||||
template <typename Buf, typename OutputIt>
|
||||
FMT_INLINE auto get_iterator(Buf& buf, OutputIt) -> decltype(buf.out()) {
|
||||
return buf.out();
|
||||
}
|
||||
template <typename T> auto get_iterator(buffer<T>& buf) -> buffer_appender<T> {
|
||||
return buffer_appender<T>(buf);
|
||||
template <typename T, typename OutputIt>
|
||||
auto get_iterator(buffer<T>&, OutputIt out) -> OutputIt {
|
||||
return out;
|
||||
}
|
||||
|
||||
template <typename T, typename Char = char, typename Enable = void>
|
||||
@ -1556,11 +1562,6 @@ FMT_END_DETAIL_NAMESPACE
|
||||
class appender : public std::back_insert_iterator<detail::buffer<char>> {
|
||||
using base = std::back_insert_iterator<detail::buffer<char>>;
|
||||
|
||||
template <typename T>
|
||||
friend auto get_buffer(appender out) -> detail::buffer<char>& {
|
||||
return detail::get_container(out);
|
||||
}
|
||||
|
||||
public:
|
||||
using std::back_insert_iterator<detail::buffer<char>>::back_insert_iterator;
|
||||
appender(base it) noexcept : base(it) {}
|
||||
@ -3224,10 +3225,9 @@ FMT_NODISCARD FMT_INLINE auto format(format_string<T...> fmt, T&&... args)
|
||||
template <typename OutputIt,
|
||||
FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, char>::value)>
|
||||
auto vformat_to(OutputIt out, string_view fmt, format_args args) -> OutputIt {
|
||||
using detail::get_buffer;
|
||||
auto&& buf = get_buffer<char>(out);
|
||||
auto&& buf = detail::get_buffer<char>(out);
|
||||
detail::vformat_to(buf, fmt, args, {});
|
||||
return detail::get_iterator(buf);
|
||||
return detail::get_iterator(buf, out);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4276,7 +4276,7 @@ auto vformat_to(OutputIt out, const Locale& loc, string_view fmt,
|
||||
using detail::get_buffer;
|
||||
auto&& buf = get_buffer<char>(out);
|
||||
detail::vformat_to(buf, fmt, args, detail::locale_ref(loc));
|
||||
return detail::get_iterator(buf);
|
||||
return detail::get_iterator(buf, out);
|
||||
}
|
||||
|
||||
template <typename OutputIt, typename Locale, typename... T,
|
||||
|
@ -145,7 +145,7 @@ auto vformat_to(OutputIt out, const S& format_str,
|
||||
-> OutputIt {
|
||||
auto&& buf = detail::get_buffer<Char>(out);
|
||||
detail::vformat_to(buf, detail::to_string_view(format_str), args);
|
||||
return detail::get_iterator(buf);
|
||||
return detail::get_iterator(buf, out);
|
||||
}
|
||||
|
||||
template <typename OutputIt, typename S, typename... Args,
|
||||
|
Loading…
Reference in New Issue
Block a user