From c9eef4572efd3d660b7b00e835fe8f1e35c08036 Mon Sep 17 00:00:00 2001 From: Roman Koshelev Date: Tue, 31 Aug 2021 07:51:06 +0300 Subject: [PATCH] Fix copy_str performance --- include/fmt/core.h | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 2f0cfb0b72c55..afb0075980eeb 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -740,19 +740,32 @@ inline auto get_container(std::back_insert_iterator it) } template -FMT_CONSTEXPR auto copy_str(InputIt begin, InputIt end, OutputIt out) +FMT_CONSTEXPR auto copy_str_constexpr(InputIt begin, InputIt end, OutputIt out) -> OutputIt { while (begin != end) *out++ = static_cast(*begin++); return out; } -template ::value)> -FMT_CONSTEXPR auto copy_str(const Char* begin, const Char* end, Char* out) - -> Char* { +template +FMT_CONSTEXPR auto copy_str(InputIt begin, InputIt end, OutputIt out) + -> OutputIt { + return copy_str_constexpr(begin, end, out); +} + +template +FMT_CONSTEXPR +typename std::enable_if +< + std::is_same::type, OutputIt>::value && + std::is_trivially_copy_assignable::value, + OutputIt* +>::type +copy_str(InputIt* begin, InputIt* end, OutputIt* out) +{ if (is_constant_evaluated()) - return copy_str(begin, end, out); + return copy_str_constexpr(begin, end, out); auto size = to_unsigned(end - begin); - memcpy(out, begin, size); + memcpy(out, begin, size * sizeof(OutputIt)); return out + size; }