github.com/ugorji/go/codec@v1.2.13-0.20240307214044-07c54c229a5a/goversion_growslice_unsafe_gte_go120.go (about)

     1  // Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved.
     2  // Use of this source code is governed by a MIT license found in the LICENSE file.
     3  
     4  //go:build go1.20 && !safe && !codec.safe && !appengine
     5  // +build go1.20,!safe,!codec.safe,!appengine
     6  
     7  package codec
     8  
     9  import (
    10  	_ "reflect" // needed for go linkname(s)
    11  	"unsafe"
    12  )
    13  
    14  func growslice(typ unsafe.Pointer, old unsafeSlice, num int) (s unsafeSlice) {
    15  	// culled from GOROOT/runtime/slice.go
    16  	num -= old.Cap - old.Len
    17  	s = rtgrowslice(old.Data, old.Cap+num, old.Cap, num, typ)
    18  	s.Len = old.Len
    19  	return
    20  }
    21  
    22  //go:linkname rtgrowslice runtime.growslice
    23  //go:noescape
    24  func rtgrowslice(oldPtr unsafe.Pointer, newLen, oldCap, num int, typ unsafe.Pointer) unsafeSlice
    25  
    26  // //go:linkname growslice reflect.growslice
    27  // //go:noescape
    28  // func growslice(typ unsafe.Pointer, old unsafeSlice, cap int) unsafeSlice