Repository navigation
docs: note that value handlers copy their stored value - #141
Merged
Merged
Conversation
Problem A value handler returns a copy of its stored value each time its case is selected. For a std::string or a std::variant holding one, that copy made a fallback 2 to 2.7 times slower than building the value in a lambda, and the docs gave no hint of it. Implementation docs/api.md explains the copy under the handler forms and shows the existing alternatives: store a cheap value and convert it with | to<T> or on<R>, or use a lambda. docs/guide/performance-tuning.md gets a Value handlers section with the same advice, a note that caching with PTN_ON does not remove the copy, and the measurements from issue #132. Tests Compiled and ran every snippet in the new text with Apple clang and GCC 13. Closes #132
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #132. Documents that a value handler (
pattern >> value)returns a copy of its stored value on every match, and points to the
forms that avoid an expensive copy:
| to<T>,on<R>, or a lambda.No code changes.
Changes
docs/api.md: a paragraph underpattern >> handleron the copy,with
_ >> Ignored{} | to<Outcome>,on<Outcome>(...)and alambda as alternatives, and a link to the tuning guide.
docs/guide/performance-tuning.md: new Value handlers section.It says when the copy is free (integers, enums, string literals,
literal tables), that
PTN_ONcaching does not remove it, shows thealternatives on a variant and a string result, and quotes the
measurements from Value handlers copy their stored value on every match #132.
Testing
acceptdefined as
Accepted accept(const Order &)) with Apple clang andGCC 13,
-std=c++17.