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

Fix copy_str performance 2 #2477

merged 1 commit into from
Sep 2, 2021

Conversation

Roman-Koshelev
Copy link
Contributor

Contrary to expectations, optimized overloading is not called

@vitaut
Copy link
Contributor

vitaut commented Aug 31, 2021

optimized overloading is not called

Could you elaborate?

@Roman-Koshelev
Copy link
Contributor Author

@vitaut answered here #2475

@vitaut
Copy link
Contributor

vitaut commented Aug 31, 2021

I'll reopen #2475 and close this one since all the discussion is there.

@vitaut vitaut closed this Aug 31, 2021
@vitaut
Copy link
Contributor

vitaut commented Aug 31, 2021

Actually, I cannot reopen #2475 because the master branch was force-pushed.

@vitaut vitaut reopened this Aug 31, 2021
Copy link
Contributor

@vitaut vitaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR.

include/fmt/core.h Outdated Show resolved Hide resolved
include/fmt/core.h Show resolved Hide resolved
return copy_str_constexpr<Char>(begin, end, out);
}

template <typename Char, typename InputIt, typename OutputIt,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably nitpicky, but since InputIt and OutputIt aren't iterators in this overload, can you rename the template parameters? I keep getting concerned when I see the "* sizeof(OutputIt)" in the call to memcpy below.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@Roman-Koshelev
Copy link
Contributor Author

I understand that we have reached an implementation that suits both of us?

Copy link
Contributor

@vitaut vitaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two small comments, otherwise looks good.

Comment on lines 743 to 749
FMT_CONSTEXPR auto copy_str_constexpr(InputIt begin, InputIt end, OutputIt out)
-> OutputIt {
while (begin != end) *out++ = static_cast<Char>(*begin++);
return out;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest merging this into the first overload of copy_str as before. The second overload can continue calling it as copy_str<Char, const Char*, Char*>(...).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it would lead to recursion, but it doesn't

return copy_str_constexpr<Char>(begin, end, out);
}

template <typename Char, typename Tp, typename Up,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Tp -> T, Up -> U for consistency with naming conventions in the library.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix

@vitaut vitaut merged commit 8029bf9 into fmtlib:master Sep 2, 2021
@vitaut
Copy link
Contributor

vitaut commented Sep 2, 2021

Thank you!

PoetaKodu pushed a commit to pacc-repo/fmt that referenced this pull request Nov 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants