From: Alexander Döring Date: Wed, 23 May 2018 22:25:12 +0000 (+0200) Subject: math/big: reduce allocations in Karatsuba case of sqr X-Git-Tag: go1.11beta1~324 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=1a5d0f83c99dbc88c276310313576627295c7f03;p=gostls13.git math/big: reduce allocations in Karatsuba case of sqr For #23221. Change-Id: If55dcf2e0706d6658f4a0863e3740437e008706c Reviewed-on: https://go-review.googlesource.com/114335 Run-TryBot: Robert Griesemer TryBot-Result: Gobot Gobot Reviewed-by: Robert Griesemer --- diff --git a/src/math/big/nat.go b/src/math/big/nat.go index dc292b4e7c..a6f79edccc 100644 --- a/src/math/big/nat.go +++ b/src/math/big/nat.go @@ -512,8 +512,7 @@ func karatsubaSqr(z, x nat) { n := len(x) if n&1 != 0 || n < karatsubaSqrThreshold || n < 2 { - z = z[:2*n] - basicSqr(z, x) + basicSqr(z[:2*n], x) return } @@ -562,13 +561,14 @@ func (z nat) sqr(x nat) nat { if alias(z, x) { z = nil // z is an alias for x - cannot reuse } - z = z.make(2 * n) if n < basicSqrThreshold { + z = z.make(2 * n) basicMul(z, x, x) return z.norm() } if n < karatsubaSqrThreshold { + z = z.make(2 * n) basicSqr(z, x) return z.norm() }