regexp: doOnePass does unnecessary check when regexp has a prefix #48891
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Small example: https://play.golang.org/p/y46WA2Dc2dI - adapted from regexp
BenchmarkAnchoredLiteralShortNonMatch
;the expression has
.*$
added to make it go down the onepass branch.This statement:
go/src/regexp/exec.go
Lines 431 to 433 in e1c294a
checks that the current runes match the op, but at regexp compile-time it is established that the start op must be
EmptyBeginText
:go/src/regexp/onepass.go
Lines 470 to 473 in e1c294a
EmptyBeginText
will always match at position 0 of the inputWhat did you expect to see?
The check
flag.match(syntax.EmptyOp(inst.Arg))
can be removed from run-time execution of the regexp, which meansi.hasPrefix
can be moved before the instruction and first runes are unpacked.What did you see instead?
In the case where a onepass regexp has a prefix which does not match, a bit of unnecessary time is spent initializing.
The text was updated successfully, but these errors were encountered: