Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix copy_str performance 2 #2477

Merged
merged 1 commit into from
Sep 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ template <bool B> using bool_constant = std::integral_constant<bool, B>;
template <typename T>
using remove_reference_t = typename std::remove_reference<T>::type;
template <typename T>
using remove_const_t = typename std::remove_const<T>::type;
template <typename T>
using remove_cvref_t = typename std::remove_cv<remove_reference_t<T>>::type;
template <typename T> struct type_identity { using type = T; };
template <typename T> using type_identity_t = typename type_identity<T>::type;
Expand Down Expand Up @@ -746,13 +748,14 @@ FMT_CONSTEXPR auto copy_str(InputIt begin, InputIt end, OutputIt out)
return out;
}

template <typename Char, FMT_ENABLE_IF(std::is_same<Char, char>::value)>
FMT_CONSTEXPR auto copy_str(const Char* begin, const Char* end, Char* out)
-> Char* {
template <typename Char, typename T, typename U,
FMT_ENABLE_IF(std::is_same<remove_const_t<T>, U>::value && is_char<U>::value)>
FMT_CONSTEXPR auto copy_str(T* begin, T* end, U* out)
-> U* {
if (is_constant_evaluated())
return copy_str<Char, const Char*, Char*>(begin, end, out);
vitaut marked this conversation as resolved.
Show resolved Hide resolved
return copy_str<Char, T*, U*>(begin, end, out);
auto size = to_unsigned(end - begin);
memcpy(out, begin, size);
memcpy(out, begin, size * sizeof(U));
return out + size;
}

Expand Down