summaryrefslogtreecommitdiff
path: root/src/pkg/big
diff options
context:
space:
mode:
authorEvan Shaw <chickencha@gmail.com>2010-04-20 21:41:58 -0700
committerEvan Shaw <chickencha@gmail.com>2010-04-20 21:41:58 -0700
commitc3704d5bf7d1e15ebd18d22146b5bc02d5c3aaec (patch)
tree9c1bcb6fa5049a7f8e1f40918744db512daf18e3 /src/pkg/big
parent48a0493a026f0e911c59c4fad2385a1f2f94663e (diff)
downloadgolang-c3704d5bf7d1e15ebd18d22146b5bc02d5c3aaec.tar.gz
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 <rsc@golang.org>
Diffstat (limited to 'src/pkg/big')
-rw-r--r--src/pkg/big/nat.go16
1 files changed, 11 insertions, 5 deletions
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]<<n | src[i-1]>>ñ
+ y := src[i-1]
+ dst[i] = x<<n | y>>ñ
+ 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
}