github.com/segmentio/encoding@v0.4.0/json/reflect.go (about) 1 //go:build go1.20 2 // +build go1.20 3 4 package json 5 6 import ( 7 "reflect" 8 "unsafe" 9 ) 10 11 func extendSlice(t reflect.Type, s *slice, n int) slice { 12 arrayType := reflect.ArrayOf(n, t.Elem()) 13 arrayData := reflect.New(arrayType) 14 reflect.Copy(arrayData.Elem(), reflect.NewAt(t, unsafe.Pointer(s)).Elem()) 15 return slice{ 16 data: unsafe.Pointer(arrayData.Pointer()), 17 len: s.len, 18 cap: n, 19 } 20 }