mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
rlp: using slices.IndexFunc
This commit is contained in:
parent
a3829178af
commit
1da6a6bbbb
2 changed files with 5 additions and 11 deletions
|
|
@ -22,6 +22,7 @@ import (
|
|||
"io"
|
||||
"math/big"
|
||||
"reflect"
|
||||
"slices"
|
||||
|
||||
"github.com/ethereum/go-ethereum/rlp/internal/rlpstruct"
|
||||
"github.com/holiman/uint256"
|
||||
|
|
@ -351,7 +352,10 @@ func makeStructWriter(typ reflect.Type) (writer, error) {
|
|||
}
|
||||
|
||||
var writer writer
|
||||
firstOptionalField := firstOptionalField(fields)
|
||||
firstOptionalField := slices.IndexFunc(fields, func(f field) bool { return f.optional })
|
||||
if firstOptionalField == -1 {
|
||||
firstOptionalField = len(fields)
|
||||
}
|
||||
if firstOptionalField == len(fields) {
|
||||
// This is the writer function for structs without any optional fields.
|
||||
writer = func(val reflect.Value, w *encBuffer) error {
|
||||
|
|
|
|||
|
|
@ -159,16 +159,6 @@ func structFields(typ reflect.Type) (fields []field, err error) {
|
|||
return fields, nil
|
||||
}
|
||||
|
||||
// firstOptionalField returns the index of the first field with "optional" tag.
|
||||
func firstOptionalField(fields []field) int {
|
||||
for i, f := range fields {
|
||||
if f.optional {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return len(fields)
|
||||
}
|
||||
|
||||
type structFieldError struct {
|
||||
typ reflect.Type
|
||||
field int
|
||||
|
|
|
|||
Loading…
Reference in a new issue