From f403916ef8866ca944f6de7231733026040907a1 Mon Sep 17 00:00:00 2001 From: visualfc Date: Wed, 13 Nov 2024 21:29:01 +0800 Subject: [PATCH] internal/lib/reflect: Value.bytesSlow --- internal/lib/reflect/value.go | 39 ++++++++++++++++------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/internal/lib/reflect/value.go b/internal/lib/reflect/value.go index 72efef52..c657e40a 100644 --- a/internal/lib/reflect/value.go +++ b/internal/lib/reflect/value.go @@ -340,28 +340,25 @@ func (v Value) Bytes() []byte { } func (v Value) bytesSlow() []byte { - /* - switch v.kind() { - case Slice: - if v.typ().Elem().Kind() != abi.Uint8 { - panic("reflect.Value.Bytes of non-byte slice") - } - // Slice is always bigger than a word; assume flagIndir. - return *(*[]byte)(v.ptr) - case Array: - if v.typ().Elem().Kind() != abi.Uint8 { - panic("reflect.Value.Bytes of non-byte array") - } - if !v.CanAddr() { - panic("reflect.Value.Bytes of unaddressable byte array") - } - p := (*byte)(v.ptr) - n := int((*arrayType)(unsafe.Pointer(v.typ())).Len) - return unsafe.Slice(p, n) + switch v.kind() { + case Slice: + if v.typ().Elem().Kind() != abi.Uint8 { + panic("reflect.Value.Bytes of non-byte slice") } - panic(&ValueError{"reflect.Value.Bytes", v.kind()}) - */ - panic("todo: reflect.Value.byteSlow") + // Slice is always bigger than a word; assume flagIndir. + return *(*[]byte)(v.ptr) + case Array: + if v.typ().Elem().Kind() != abi.Uint8 { + panic("reflect.Value.Bytes of non-byte array") + } + if !v.CanAddr() { + panic("reflect.Value.Bytes of unaddressable byte array") + } + p := (*byte)(v.ptr) + n := int((*arrayType)(unsafe.Pointer(v.typ())).Len) + return unsafe.Slice(p, n) + } + panic(&ValueError{"reflect.Value.Bytes", v.kind()}) } // runes returns v's underlying value.