mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-07 15:38:37 +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"
|
"reflect"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/common/math"
|
||||||
"github.com/holiman/uint256"
|
"github.com/holiman/uint256"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -145,9 +146,6 @@ func (buf *encBuffer) writeString(s string) {
|
||||||
buf.writeBytes([]byte(s))
|
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.
|
// writeBigInt writes i as an integer.
|
||||||
func (buf *encBuffer) writeBigInt(i *big.Int) {
|
func (buf *encBuffer) writeBigInt(i *big.Int) {
|
||||||
bitlen := i.BitLen()
|
bitlen := i.BitLen()
|
||||||
|
|
@ -161,15 +159,8 @@ func (buf *encBuffer) writeBigInt(i *big.Int) {
|
||||||
length := ((bitlen + 7) & -8) >> 3
|
length := ((bitlen + 7) & -8) >> 3
|
||||||
buf.encodeStringHeader(length)
|
buf.encodeStringHeader(length)
|
||||||
buf.str = append(buf.str, make([]byte, length)...)
|
buf.str = append(buf.str, make([]byte, length)...)
|
||||||
index := length
|
|
||||||
bytesBuf := buf.str[len(buf.str)-length:]
|
bytesBuf := buf.str[len(buf.str)-length:]
|
||||||
for _, d := range i.Bits() {
|
math.ReadBits(i, bytesBuf)
|
||||||
for j := 0; j < wordBytes && index > 0; j++ {
|
|
||||||
index--
|
|
||||||
bytesBuf[index] = byte(d)
|
|
||||||
d >>= 8
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// writeUint256 writes z as an integer.
|
// writeUint256 writes z as an integer.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue