From 0bd308ff27822378dc2db77d6dd0ad3c15ed2e08 Mon Sep 17 00:00:00 2001 From: Rob Findley Date: Wed, 17 Mar 2021 12:42:19 -0400 Subject: [PATCH] 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 Trust: Robert Griesemer Run-TryBot: Robert Findley TryBot-Result: Go Bot Reviewed-by: Robert Griesemer --- src/go/parser/parser.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/go/parser/parser.go b/src/go/parser/parser.go index ed1867b3b3..b86d6bad46 100644 --- a/src/go/parser/parser.go +++ b/src/go/parser/parser.go @@ -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 }