Skip to content

Commit

Permalink
Optimize Not error condition (#363)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnynek authored Jan 29, 2022
1 parent 5125491 commit 2e916ff
Showing 1 changed file with 9 additions and 2 deletions.
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

0 comments on commit 2e916ff

Please sign in to comment.