improved performance by removing penalty of copying a char span via abstracted output iterator

This commit is contained in:
Pavel Novikov 2021-10-13 17:19:30 +03:00
parent dcd282bb26
commit c91cce9194
No known key found for this signature in database
GPG Key ID: AEC4E958FA860F27

View File

@ -86,7 +86,8 @@ FMT_CONSTEXPR To lossless_integral_conversion(const From from, int& ec) {
}
}
if (detail::const_check(!F::is_signed && T::is_signed && F::digits >= T::digits) &&
if (detail::const_check(!F::is_signed && T::is_signed &&
F::digits >= T::digits) &&
from > static_cast<From>(detail::max_value<To>())) {
ec = 1;
return {};
@ -582,13 +583,13 @@ template <typename Char> struct formatter<std::tm, Char> {
detail::write_digit2_separated(buf + 2, year % 100,
detail::to_unsigned(tm.tm_mon + 1),
detail::to_unsigned(tm.tm_mday), '-');
return std::copy_n(buf, sizeof(buf), ctx.out());
return detail::copy_str<Char>(std::begin(buf), std::end(buf), ctx.out());
} else if (spec_ == spec::hh_mm_ss) {
char buf[8];
detail::write_digit2_separated(buf, detail::to_unsigned(tm.tm_hour),
detail::to_unsigned(tm.tm_min),
detail::to_unsigned(tm.tm_sec), ':');
return std::copy_n(buf, sizeof(buf), ctx.out());
return detail::copy_str<Char>(std::begin(buf), std::end(buf), ctx.out());
}
basic_memory_buffer<Char> tm_format;
tm_format.append(specs.begin(), specs.end());
@ -610,7 +611,7 @@ template <typename Char> struct formatter<std::tm, Char> {
buf.reserve(buf.capacity() + (size > MIN_GROWTH ? size : MIN_GROWTH));
}
// Remove the extra space.
return std::copy(buf.begin(), buf.end() - 1, ctx.out());
return detail::copy_str<Char>(buf.begin(), buf.end() - 1, ctx.out());
}
};