mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: unify reflect, string and slice copy runtime functions
Use a common runtime slicecopy function to copy strings or slices into slices. This deduplicates similar code previously used in reflect.slicecopy and runtime.stringslicecopy. Change-Id: I09572ff0647a9e12bb5c6989689ce1c43f16b7f1 Reviewed-on: https://go-review.googlesource.com/c/go/+/254658 Run-TryBot: Martin Möhrmann <moehrmann@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Martin Möhrmann <moehrmann@google.com> Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
parent
eaa97fbf20
commit
790fa1c546
6 changed files with 248 additions and 304 deletions
|
|
@ -928,16 +928,20 @@ func (o Op) IsSlice3() bool {
|
|||
return false
|
||||
}
|
||||
|
||||
// slicePtrLen extracts the pointer and length from a slice.
|
||||
// backingArrayPtrLen extracts the pointer and length from a slice or string.
|
||||
// This constructs two nodes referring to n, so n must be a cheapexpr.
|
||||
func (n *Node) slicePtrLen() (ptr, len *Node) {
|
||||
func (n *Node) backingArrayPtrLen() (ptr, len *Node) {
|
||||
var init Nodes
|
||||
c := cheapexpr(n, &init)
|
||||
if c != n || init.Len() != 0 {
|
||||
Fatalf("slicePtrLen not cheap: %v", n)
|
||||
Fatalf("backingArrayPtrLen not cheap: %v", n)
|
||||
}
|
||||
ptr = nod(OSPTR, n, nil)
|
||||
ptr.Type = n.Type.Elem().PtrTo()
|
||||
if n.Type.IsString() {
|
||||
ptr.Type = types.Types[TUINT8].PtrTo()
|
||||
} else {
|
||||
ptr.Type = n.Type.Elem().PtrTo()
|
||||
}
|
||||
len = nod(OLEN, n, nil)
|
||||
len.Type = types.Types[TINT]
|
||||
return ptr, len
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue