Skip to content

Commit ef074b6

Browse files
authored
Rely on new reflect.Value.Bytes semantics in Go 1.19 (#249)
The Bytes method now operates on addressable byte arrays.
1 parent a213b67 commit ef074b6

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

arshal_default.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,7 @@ func makeBytesArshaler(t reflect.Type, fncs *arshaler) *arshaler {
228228
}
229229
}
230230
val := enc.UnusedBuffer()
231-
var b []byte
232-
if va.Kind() == reflect.Array {
233-
// TODO(https://go.dev/issue/47066): Avoid reflect.Value.Slice.
234-
b = va.Slice(0, va.Len()).Bytes()
235-
} else {
236-
b = va.Bytes()
237-
}
231+
b := va.Bytes()
238232
n := len(`"`) + encodedLen(len(b)) + len(`"`)
239233
if cap(val) < n {
240234
val = make([]byte, n)
@@ -290,16 +284,13 @@ func makeBytesArshaler(t reflect.Type, fncs *arshaler) *arshaler {
290284
n--
291285
}
292286
n = decodedLen(n)
293-
var b []byte
287+
b := va.Bytes()
294288
if va.Kind() == reflect.Array {
295-
// TODO(https://go.dev/issue/47066): Avoid reflect.Value.Slice.
296-
b = va.Slice(0, va.Len()).Bytes()
297289
if n != len(b) {
298290
err := fmt.Errorf("decoded base64 length of %d mismatches array length of %d", n, len(b))
299291
return &SemanticError{action: "unmarshal", JSONKind: k, GoType: t, Err: err}
300292
}
301293
} else {
302-
b = va.Bytes()
303294
if b == nil || cap(b) < n {
304295
b = make([]byte, n)
305296
} else {

0 commit comments

Comments
 (0)