From c3704d5bf7d1e15ebd18d22146b5bc02d5c3aaec Mon Sep 17 00:00:00 2001 From: Evan Shaw Date: Tue, 20 Apr 2010 21:41:58 -0700 Subject: big: eliminate redundant array lookups This gives about a 6% performance improvement to pidigits. Thanks to Russ for the suggestion. R=rsc, gri CC=golang-dev http://codereview.appspot.com/957041 Committer: Russ Cox --- src/pkg/big/nat.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/pkg/big/nat.go b/src/pkg/big/nat.go index 456952aa8..6c7e6e722 100644 --- a/src/pkg/big/nat.go +++ b/src/pkg/big/nat.go @@ -544,13 +544,16 @@ func shiftLeft(dst, src []Word, n uint) { } ñ := _W - n + x := src[len(src)-1] if len(dst) > len(src) { - dst[len(src)] |= src[len(src)-1] >> ñ + dst[len(src)] = x >> ñ } for i := len(src) - 1; i >= 1; i-- { - dst[i] = src[i]<>ñ + y := src[i-1] + dst[i] = x<>ñ + x = y } - dst[0] = src[0] << n + dst[0] = x << n } @@ -560,10 +563,13 @@ func shiftRight(dst, src []Word, n uint) { } ñ := _W - n + x := src[0] for i := 0; i < len(src)-1; i++ { - dst[i] = src[i]>>n | src[i+1]<<ñ + y := src[i+1] + dst[i] = x>>n | y<<ñ + x = y } - dst[len(src)-1] = src[len(src)-1] >> n + dst[len(src)-1] = x >> n } -- cgit v1.2.3