From: Robert Griesemer Date: Thu, 12 Jul 2012 21:12:50 +0000 (-0700) Subject: math/big: minor performance tuning X-Git-Tag: go1.1rc2~2814 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=98ca655919622659598988f7ed420706858ad4c0;p=gostls13.git math/big: minor performance tuning Reuse temporary slice to avoid extra allocations (originally done correctly by remyoudompheng@gmail.com in https://golang.org/cl/6345075/). benchmark old ns/op new ns/op delta BenchmarkHilbert 6252790 6262304 +0.15% BenchmarkMul 45827438 45301002 -1.15% R=r CC=golang-dev https://golang.org/cl/6346097 --- diff --git a/src/pkg/math/big/nat.go b/src/pkg/math/big/nat.go index 43d53d17a6..04f5dfd8ba 100644 --- a/src/pkg/math/big/nat.go +++ b/src/pkg/math/big/nat.go @@ -438,8 +438,9 @@ func (z nat) mul(x, y nat) nat { // add x0*y1*b x0 := x0.norm() - y1 := y[k:] // y1 is normalized because y is - addAt(z, t.mul(x0, y1), k) + y1 := y[k:] // y1 is normalized because y is + t = t.mul(x0, y1) // update t so we don't lose t's underlying array + addAt(z, t, k) // add xi*y0<