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 #2475

Closed
wants to merge 1 commit into from
Closed
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: 1 addition & 12 deletions include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -742,18 +742,7 @@ inline auto get_container(std::back_insert_iterator<Container> it)
template <typename Char, typename InputIt, typename OutputIt>
FMT_CONSTEXPR auto copy_str(InputIt begin, InputIt end, OutputIt out)
-> OutputIt {
while (begin != end) *out++ = static_cast<Char>(*begin++);
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* {
if (is_constant_evaluated())
return copy_str<Char, const Char*, Char*>(begin, end, out);
auto size = to_unsigned(end - begin);
memcpy(out, begin, size);
return out + size;
return std::copy(begin, end, out);
}

/**
Expand Down