mirror of
https://github.com/golang/go
synced 2024-09-30 04:34:33 -06:00
go/parser: avoid formatting a panic message if an assertion succeeds
tryResolve is an extremely hot method on the parser. Eliminating this formatting led to a 20% performance improvement in BenchmarkParse. Change-Id: Idf8850404bd72d45d1351356427a85086422ea68 Reviewed-on: https://go-review.googlesource.com/c/go/+/302629 Trust: Robert Findley <rfindley@google.com> Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
70d54df4f6
commit
0bd308ff27
@ -181,7 +181,10 @@ func (p *parser) tryResolve(x ast.Expr, collectUnresolved bool) {
|
||||
if ident == nil {
|
||||
return
|
||||
}
|
||||
assert(ident.Obj == nil, fmt.Sprintf("identifier %s already declared or resolved", ident.Name))
|
||||
// Don't use assert here, to avoid needless formatting of the message below.
|
||||
if ident.Obj != nil {
|
||||
panic(fmt.Sprintf("identifier %s already declared or resolved", ident.Name))
|
||||
}
|
||||
if ident.Name == "_" {
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user