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.
Alternative approach to #418.
These lines added in #400 caused the problem since the result of multiple
append
calls can return two slices backed by the same backing array. See demo here: https://go.dev/play/p/2FGKuCvCUKz. The bug only surfaces under specific conditions when the capacity ofparser.context
is increased by more than 1 due to this append call. This PR removes theappend
calls that cause this issue, as well as optimizing some places where you don't need toappend
since the length is predetermined -- that is, instead of:prefer:
For the record, I think #418 is the better fix since it doesn't rely on ensuring that
p.context = append(p.context, ...)
is never called and thus more future-proof, however, I'm not sure why these lines were added - maybe performance - so can't be sure if people (cc @arp242) like the idea of removing it.Fixes #417