Skip to content

Commit d1ac000

Browse files
committed
reflect: Use Value.Len instead of conversion to slice header.
This change is functionally equivalent, but reduces reliance on unsafe features. This would allow GopherJS to avoid an additional patch to the standard library we'd have to maintain in order to remain compatible with Go 1.17+.
1 parent ad97d20 commit d1ac000

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

src/reflect/value.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2940,8 +2940,7 @@ func (v Value) CanConvert(t Type) bool {
29402940
// from slice to pointer-to-array.
29412941
if vt.Kind() == Slice && t.Kind() == Ptr && t.Elem().Kind() == Array {
29422942
n := t.Elem().Len()
2943-
h := (*unsafeheader.Slice)(v.ptr)
2944-
if n > h.Len {
2943+
if n > v.Len() {
29452944
return false
29462945
}
29472946
}

0 commit comments

Comments
 (0)