File: slice.go

package info (click to toggle)
golang-github-segmentio-encoding 0.5.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 14,468 kB
  • sloc: makefile: 286
file content (44 lines) | stat: -rw-r--r-- 844 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package runtime_reflect

import "unsafe"

type Slice struct {
	data unsafe.Pointer
	len  int
	cap  int
}

func (s *Slice) Cap() int {
	return s.cap
}

func (s *Slice) Len() int {
	return s.len
}

func (s *Slice) SetLen(n int) {
	s.len = n
}

func (s *Slice) Index(i int, elemSize uintptr) unsafe.Pointer {
	return unsafe.Pointer(uintptr(s.data) + (uintptr(i) * elemSize))
}

func MakeSlice(elemType unsafe.Pointer, len, cap int) Slice {
	return Slice{
		data: newarray(elemType, cap),
		len:  len,
		cap:  cap,
	}
}

func CopySlice(elemType unsafe.Pointer, dst, src Slice) int {
	return typedslicecopy(elemType, dst, src)
}

//go:linkname newarray runtime.newarray
func newarray(t unsafe.Pointer, n int) unsafe.Pointer

//go:linkname typedslicecopy runtime.typedslicecopy
//go:noescape
func typedslicecopy(t unsafe.Pointer, dst, src Slice) int