diff options
author | Robert Griesemer <gri@golang.org> | 2019-01-08 22:39:13 -0800 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2019-01-09 16:10:07 +0000 |
commit | 8765a786b6e8199959bba8244ac5f95aa3eb9474 (patch) | |
tree | f892d805ad4b5090bfbb7d8124fd004802187559 | |
parent | a14ed2a82a1563ba89e1f22ab517bf3c9abe416f (diff) | |
download | go-8765a786b6e8199959bba8244ac5f95aa3eb9474.tar.gz go-8765a786b6e8199959bba8244ac5f95aa3eb9474.zip |
go/types: don't create new context string for each argument of each call
The argument context string is only used in error messages. Don't format
the function AST into a string for every single argument of every single
call that is type-checked. Instead do it once per call (still not great,
but much much better).
Performance optimization.
Change-Id: Iec87f9ad34128d7b3eee58577ad37dbaa8e6db44
Reviewed-on: https://go-review.googlesource.com/c/157037
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
-rw-r--r-- | src/go/types/call.go | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/go/types/call.go b/src/go/types/call.go index 0ea1623903..1abc1d8a5e 100644 --- a/src/go/types/call.go +++ b/src/go/types/call.go @@ -233,6 +233,7 @@ func (check *Checker) arguments(x *operand, call *ast.CallExpr, sig *Signature, } // evaluate arguments + context := check.sprintf("argument to %s", call.Fun) for i := 0; i < n; i++ { arg(x, i) if x.mode != invalid { @@ -240,7 +241,7 @@ func (check *Checker) arguments(x *operand, call *ast.CallExpr, sig *Signature, if i == n-1 && call.Ellipsis.IsValid() { ellipsis = call.Ellipsis } - check.argument(call.Fun, sig, i, x, ellipsis) + check.argument(call.Fun, sig, i, x, ellipsis, context) } } @@ -258,7 +259,7 @@ func (check *Checker) arguments(x *operand, call *ast.CallExpr, sig *Signature, // argument checks passing of argument x to the i'th parameter of the given signature. // If ellipsis is valid, the argument is followed by ... at that position in the call. -func (check *Checker) argument(fun ast.Expr, sig *Signature, i int, x *operand, ellipsis token.Pos) { +func (check *Checker) argument(fun ast.Expr, sig *Signature, i int, x *operand, ellipsis token.Pos, context string) { check.singleValue(x) if x.mode == invalid { return @@ -298,7 +299,7 @@ func (check *Checker) argument(fun ast.Expr, sig *Signature, i int, x *operand, typ = typ.(*Slice).elem } - check.assignment(x, typ, check.sprintf("argument to %s", fun)) + check.assignment(x, typ, context) } func (check *Checker) selector(x *operand, e *ast.SelectorExpr) { |