Commit 008c62b2 authored by Robert Griesemer's avatar Robert Griesemer

math/big: optimize common case of Int.Bit(0)

R=golang-dev, dsymonds, rsc
CC=golang-dev
https://golang.org/cl/6306069
parent ea3c3bb3
......@@ -697,6 +697,13 @@ func (z *Int) Rsh(x *Int, n uint) *Int {
// Bit returns the value of the i'th bit of x. That is, it
// returns (x>>i)&1. The bit index i must be >= 0.
func (x *Int) Bit(i int) uint {
if i == 0 {
// optimization for common case: odd/even test of x
if len(x.abs) > 0 {
return uint(x.abs[0] & 1) // bit 0 is same for -x
}
return 0
}
if i < 0 {
panic("negative bit index")
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment