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

Optimize Not error condition #363

Merged
merged 1 commit into from
Jan 29, 2022
Merged
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
11 changes: 9 additions & 2 deletions core/shared/src/main/scala/cats/parse/Parser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2934,10 +2934,17 @@ object Parser {
state.error = null
} else {
// under succeeded but we expected failure here
val matchedStr = state.str.substring(offset, state.offset)
// record the current offset before it changes
// in a potential operation
val offsetErr = state.offset
// we don't reset the offset, so if the underlying parser
// advanced it will fail in a OneOf
state.error = Eval.later(Chain.one(Expectation.ExpectedFailureAt(offset, matchedStr)))
state.error = Eval.later {
// put as much as possible here, but cannot reference
// mutable vars
val matchedStr = state.str.substring(offset, offsetErr)
Chain.one(Expectation.ExpectedFailureAt(offset, matchedStr))
}
}

state.offset = offset
Expand Down