فهرست منبع

Revert "This might be more performant in some cases"

This reverts commit 105ba3876527f3346574cd2e00d090b95396b3fe.
Ben Hood 11 سال پیش
والد
کامیت
49b8f047ee
1فایلهای تغییر یافته به همراه4 افزوده شده و 11 حذف شده
  1. 4 11
      marshal.go

+ 4 - 11
marshal.go

@@ -15,7 +15,7 @@ import (
 )
 
 var (
-	zero = big.NewInt(0)
+	bigOne = big.NewInt(1)
 )
 
 // Marshaler is the interface implemented by objects that can marshal
@@ -729,7 +729,7 @@ func unmarshalDecimal(info *TypeInfo, data []byte, value interface{}) error {
 func decBigInt2C(data []byte) *big.Int {
 	n := new(big.Int).SetBytes(data)
 	if len(data) > 0 && data[0]&0x80 > 0 {
-		n.Sub(n, exp2(new(big.Int), len(data)*8))
+		n.Sub(n, new(big.Int).Lsh(bigOne, uint(len(data))*8))
 	}
 	return n
 }
@@ -747,8 +747,8 @@ func encBigInt2C(n *big.Int) []byte {
 		}
 		return b
 	case -1:
-		length := (n.BitLen()/8 + 1) * 8
-		b := new(big.Int).Add(n, exp2(new(big.Int), length)).Bytes()
+		length := uint(n.BitLen()/8+1) * 8
+		b := new(big.Int).Add(n, new(big.Int).Lsh(bigOne, length)).Bytes()
 		// When the most significant bit is on a byte
 		// boundary, we can get some extra significant
 		// bits, so strip them off when that happens.
@@ -760,13 +760,6 @@ func encBigInt2C(n *big.Int) []byte {
 	return nil
 }
 
-// exp2 sets z to 2**n.
-func exp2(z *big.Int, n int) *big.Int {
-	z.Set(zero)
-	z.SetBit(z, n, 1)
-	return z
-}
-
 func marshalTimestamp(info *TypeInfo, value interface{}) ([]byte, error) {
 	switch v := value.(type) {
 	case Marshaler: