github.com/neilotoole/jsoncolor@v0.7.2-0.20231115150201-1637fae69be1/reflect.go (about) 1 //go:build go1.15 2 // +build go1.15 3 4 package jsoncolor 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 }