From 789452a5d875560d4dd5ac479a8d6f4f991d188d Mon Sep 17 00:00:00 2001 From: cuiweixie Date: Wed, 13 Aug 2025 16:41:49 +0800 Subject: [PATCH] rlp: opt intsize --- rlp/encode.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rlp/encode.go b/rlp/encode.go index 623932a90b..de2b02f629 100644 --- a/rlp/encode.go +++ b/rlp/encode.go @@ -21,6 +21,7 @@ import ( "fmt" "io" "math/big" + "math/bits" "reflect" "github.com/ethereum/go-ethereum/rlp/internal/rlpstruct" @@ -487,9 +488,8 @@ func putint(b []byte, i uint64) (size int) { // intsize computes the minimum number of bytes required to store i. func intsize(i uint64) (size int) { - for size = 1; ; size++ { - if i >>= 8; i == 0 { - return size - } + if i == 0 { + return 1 } + return (bits.Len64(i) + 7) / 8 }