mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-02-26 07:37:20 +00:00
rlp: remove workaround for Value.Bytes (#32433)
As of Go 1.19, it is permitted to call Bytes() on a reflect.Value representing an adressable byte array. So we can remove our workaround, undoing #22924. https://go.dev/doc/go1.19#reflectpkgreflect > The method [Value.Bytes](https://go.dev/pkg/reflect/#Value.Bytes) now accepts addressable arrays in addition to slices.
This commit is contained in:
parent
1d29e3ec0e
commit
1693a48f8c
4 changed files with 2 additions and 60 deletions
|
|
@ -371,7 +371,7 @@ func decodeByteArray(s *Stream, val reflect.Value) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
slice := byteArrayBytes(val, val.Len())
|
||||
slice := val.Bytes()
|
||||
switch kind {
|
||||
case Byte:
|
||||
if len(slice) == 0 {
|
||||
|
|
|
|||
|
|
@ -240,7 +240,6 @@ func makeByteArrayWriter(typ reflect.Type) writer {
|
|||
case 1:
|
||||
return writeLengthOneByteArray
|
||||
default:
|
||||
length := typ.Len()
|
||||
return func(val reflect.Value, w *encBuffer) error {
|
||||
if !val.CanAddr() {
|
||||
// Getting the byte slice of val requires it to be addressable. Make it
|
||||
|
|
@ -249,7 +248,7 @@ func makeByteArrayWriter(typ reflect.Type) writer {
|
|||
copy.Set(val)
|
||||
val = copy
|
||||
}
|
||||
slice := byteArrayBytes(val, length)
|
||||
slice := val.Bytes()
|
||||
w.encodeStringHeader(len(slice))
|
||||
w.str = append(w.str, slice...)
|
||||
return nil
|
||||
|
|
|
|||
27
rlp/safe.go
27
rlp/safe.go
|
|
@ -1,27 +0,0 @@
|
|||
// Copyright 2021 The go-ethereum Authors
|
||||
// This file is part of the go-ethereum library.
|
||||
//
|
||||
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//go:build nacl || js || !cgo
|
||||
// +build nacl js !cgo
|
||||
|
||||
package rlp
|
||||
|
||||
import "reflect"
|
||||
|
||||
// byteArrayBytes returns a slice of the byte array v.
|
||||
func byteArrayBytes(v reflect.Value, length int) []byte {
|
||||
return v.Slice(0, length).Bytes()
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
// Copyright 2021 The go-ethereum Authors
|
||||
// This file is part of the go-ethereum library.
|
||||
//
|
||||
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//go:build !nacl && !js && cgo
|
||||
// +build !nacl,!js,cgo
|
||||
|
||||
package rlp
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// byteArrayBytes returns a slice of the byte array v.
|
||||
func byteArrayBytes(v reflect.Value, length int) []byte {
|
||||
return unsafe.Slice((*byte)(unsafe.Pointer(v.UnsafeAddr())), length)
|
||||
}
|
||||
Loading…
Reference in a new issue