Change-Id: Id07f16d14133ee539bc2880b39641c42418fa6e2
GitHub-Last-Rev:
7b327d508f677f2476d24f046d25921f4599dd9a
GitHub-Pull-Request: golang/go#67319
Reviewed-on: https://go-review.googlesource.com/c/go/+/585016
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
< hash/adler32, hash/crc32, hash/crc64, hash/fnv;
# math/big
- FMT, encoding/binary, math/rand
+ FMT, math/rand
< math/big;
# compression
package big
import (
- "encoding/binary"
"errors"
"fmt"
+ "internal/byteorder"
)
// Gob codec version. Permits backward-compatible changes to the encoding.
b |= 1
}
buf[1] = b
- binary.BigEndian.PutUint32(buf[2:], x.prec)
+ byteorder.BePutUint32(buf[2:], x.prec)
if x.form == finite {
- binary.BigEndian.PutUint32(buf[6:], uint32(x.exp))
+ byteorder.BePutUint32(buf[6:], uint32(x.exp))
x.mant[len(x.mant)-n:].bytes(buf[10:]) // cut off unused trailing words
}
z.acc = Accuracy((b>>3)&3) - 1
z.form = form((b >> 1) & 3)
z.neg = b&1 != 0
- z.prec = binary.BigEndian.Uint32(buf[2:])
+ z.prec = byteorder.BeUint32(buf[2:])
if z.form == finite {
if len(buf) < 10 {
return errors.New("Float.GobDecode: buffer too small for finite form float")
}
- z.exp = int32(binary.BigEndian.Uint32(buf[6:]))
+ z.exp = int32(byteorder.BeUint32(buf[6:]))
z.mant = z.mant.setBytes(buf[10:])
}
package big
import (
- "encoding/binary"
+ "internal/byteorder"
"math/bits"
"math/rand"
"sync"
// bigEndianWord returns the contents of buf interpreted as a big-endian encoded Word value.
func bigEndianWord(buf []byte) Word {
if _W == 64 {
- return Word(binary.BigEndian.Uint64(buf))
+ return Word(byteorder.BeUint64(buf))
}
- return Word(binary.BigEndian.Uint32(buf))
+ return Word(byteorder.BeUint32(buf))
}
// setBytes interprets buf as the bytes of a big-endian unsigned
package big
import (
- "encoding/binary"
"errors"
"fmt"
+ "internal/byteorder"
"math"
)
// this should never happen
return nil, errors.New("Rat.GobEncode: numerator too large")
}
- binary.BigEndian.PutUint32(buf[j-4:j], uint32(n))
+ byteorder.BePutUint32(buf[j-4:j], uint32(n))
j -= 1 + 4
b := ratGobVersion << 1 // make space for sign bit
if x.a.neg {
return fmt.Errorf("Rat.GobDecode: encoding version %d not supported", b>>1)
}
const j = 1 + 4
- ln := binary.BigEndian.Uint32(buf[j-4 : j])
+ ln := byteorder.BeUint32(buf[j-4 : j])
if uint64(ln) > math.MaxInt-j {
return errors.New("Rat.GobDecode: invalid length")
}
import (
"errors"
+ "internal/byteorder"
"math/bits"
)
p.lo = seed2
}
-// binary.bigEndian.Uint64, copied to avoid dependency
-func beUint64(b []byte) uint64 {
- _ = b[7] // bounds check hint to compiler; see golang.org/issue/14808
- return uint64(b[7]) | uint64(b[6])<<8 | uint64(b[5])<<16 | uint64(b[4])<<24 |
- uint64(b[3])<<32 | uint64(b[2])<<40 | uint64(b[1])<<48 | uint64(b[0])<<56
-}
-
-// binary.bigEndian.PutUint64, copied to avoid dependency
-func bePutUint64(b []byte, v uint64) {
- _ = b[7] // early bounds check to guarantee safety of writes below
- b[0] = byte(v >> 56)
- b[1] = byte(v >> 48)
- b[2] = byte(v >> 40)
- b[3] = byte(v >> 32)
- b[4] = byte(v >> 24)
- b[5] = byte(v >> 16)
- b[6] = byte(v >> 8)
- b[7] = byte(v)
-}
-
// MarshalBinary implements the encoding.BinaryMarshaler interface.
func (p *PCG) MarshalBinary() ([]byte, error) {
b := make([]byte, 20)
copy(b, "pcg:")
- bePutUint64(b[4:], p.hi)
- bePutUint64(b[4+8:], p.lo)
+ byteorder.BePutUint64(b[4:], p.hi)
+ byteorder.BePutUint64(b[4+8:], p.lo)
return b, nil
}
if len(data) != 20 || string(data[:4]) != "pcg:" {
return errUnmarshalPCG
}
- p.hi = beUint64(data[4:])
- p.lo = beUint64(data[4+8:])
+ p.hi = byteorder.BeUint64(data[4:])
+ p.lo = byteorder.BeUint64(data[4+8:])
return nil
}