From 98ca655919622659598988f7ed420706858ad4c0 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 12 Jul 2012 14:12:50 -0700 Subject: [PATCH] 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 --- src/pkg/math/big/nat.go | 13 ++++++++----- src/pkg/math/big/nat_test.go | 4 ++-- 2 files changed, 10 insertions(+), 7 deletions(-) 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<