mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-02-26 07:37:20 +00:00
rlp: refactor to use maths.ReadBits (#32432)
This commit is contained in:
parent
997dff4fae
commit
44fc0c8706
1 changed files with 2 additions and 11 deletions
|
|
@ -23,6 +23,7 @@ import (
|
|||
"reflect"
|
||||
"sync"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common/math"
|
||||
"github.com/holiman/uint256"
|
||||
)
|
||||
|
||||
|
|
@ -145,9 +146,6 @@ func (buf *encBuffer) writeString(s string) {
|
|||
buf.writeBytes([]byte(s))
|
||||
}
|
||||
|
||||
// wordBytes is the number of bytes in a big.Word
|
||||
const wordBytes = (32 << (uint64(^big.Word(0)) >> 63)) / 8
|
||||
|
||||
// writeBigInt writes i as an integer.
|
||||
func (buf *encBuffer) writeBigInt(i *big.Int) {
|
||||
bitlen := i.BitLen()
|
||||
|
|
@ -161,15 +159,8 @@ func (buf *encBuffer) writeBigInt(i *big.Int) {
|
|||
length := ((bitlen + 7) & -8) >> 3
|
||||
buf.encodeStringHeader(length)
|
||||
buf.str = append(buf.str, make([]byte, length)...)
|
||||
index := length
|
||||
bytesBuf := buf.str[len(buf.str)-length:]
|
||||
for _, d := range i.Bits() {
|
||||
for j := 0; j < wordBytes && index > 0; j++ {
|
||||
index--
|
||||
bytesBuf[index] = byte(d)
|
||||
d >>= 8
|
||||
}
|
||||
}
|
||||
math.ReadBits(i, bytesBuf)
|
||||
}
|
||||
|
||||
// writeUint256 writes z as an integer.
|
||||
|
|
|
|||
Loading…
Reference in a new issue