Optimized Parse.Sequence(...) combinator #94
Merged
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.
Parse.Sequence()
is a non-allocating alternative toThen()
. It avoids construction of nested parsers by flattening out the sequence.A comparison from the benches:
Results from running this on a small input:
It's not expected that
Sequence
would always replaceThen
, but the difference in allocs will help boost possible "v3" perf quite a bit, in conjunction with a few other planned changes.The PR is setting up for a longer, deeper 3.0 where some breaking changes are expected. Rather than start depending on System.ValueTuple I made the (possibly rash) move to drop every target except .NET Standard 2.0. We can reconsider this down the track, but for now it'll keep the work-in-progress clean and simple.
The signature of
Sequence()
could be extended to include an additional "selector" argument, avoiding the need for a chainedSelect()
call to unpack the tuple. Current C# limitations make lambdas accepting tuples a bit ugly - but if there's any hope this will improve, my preferences tip towards the cleaner signature used in the current PR version.