]> Cypherpunks repositories - gostls13.git/commitdiff
go/parser: avoid formatting a panic message if an assertion succeeds
authorRob Findley <rfindley@google.com>
Wed, 17 Mar 2021 16:42:19 +0000 (12:42 -0400)
committerRobert Findley <rfindley@google.com>
Wed, 17 Mar 2021 17:13:50 +0000 (17:13 +0000)
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>
src/go/parser/parser.go

index ed1867b3b3fed452191d10512dba989e66dbb592..b86d6bad46c4f6f7f34eb91f825ce44e5f566068 100644 (file)
@@ -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
        }