rlp: refactor to use maths.ReadBits (#32432)
Some checks are pending
/ Linux Build (push) Waiting to run
/ Linux Build (arm) (push) Waiting to run
/ Windows Build (push) Waiting to run
/ Docker Image (push) Waiting to run

This commit is contained in:
cui 2025-08-21 09:37:08 +08:00 committed by GitHub
parent 997dff4fae
commit 44fc0c8706
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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.