mirror of
https://github.com/golang/go
synced 2024-11-23 19:00:04 -07:00
runtime: simplify typedmemmovepartial
The offset is always a multiple of the pointer size. Change-Id: I790e087e89a081044a3ec35d99880533a4c929bd Reviewed-on: https://go-review.googlesource.com/c/go/+/227540 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Austin Clements <austin@google.com>
This commit is contained in:
parent
ddfc55b076
commit
b4bb47d88f
@ -193,32 +193,18 @@ func reflectlite_typedmemmove(typ *_type, dst, src unsafe.Pointer) {
|
|||||||
|
|
||||||
// typedmemmovepartial is like typedmemmove but assumes that
|
// typedmemmovepartial is like typedmemmove but assumes that
|
||||||
// dst and src point off bytes into the value and only copies size bytes.
|
// dst and src point off bytes into the value and only copies size bytes.
|
||||||
|
// off must be a multiple of sys.PtrSize.
|
||||||
//go:linkname reflect_typedmemmovepartial reflect.typedmemmovepartial
|
//go:linkname reflect_typedmemmovepartial reflect.typedmemmovepartial
|
||||||
func reflect_typedmemmovepartial(typ *_type, dst, src unsafe.Pointer, off, size uintptr) {
|
func reflect_typedmemmovepartial(typ *_type, dst, src unsafe.Pointer, off, size uintptr) {
|
||||||
if writeBarrier.needed && typ.ptrdata != 0 && size >= sys.PtrSize {
|
if writeBarrier.needed && typ.ptrdata > off && size >= sys.PtrSize {
|
||||||
// Pointer-align start address for bulk barrier.
|
if off&(sys.PtrSize-1) != 0 {
|
||||||
adst, asrc, asize := dst, src, size
|
panic("reflect: internal error: misaligned offset")
|
||||||
ptrdata := typ.ptrdata
|
|
||||||
if ptrdata > off {
|
|
||||||
ptrdata -= off
|
|
||||||
} else {
|
|
||||||
ptrdata = 0
|
|
||||||
}
|
}
|
||||||
if frag := -off & (sys.PtrSize - 1); frag != 0 {
|
pwsize := alignDown(size, sys.PtrSize)
|
||||||
adst = add(dst, frag)
|
if poff := typ.ptrdata - off; pwsize > poff {
|
||||||
asrc = add(src, frag)
|
pwsize = poff
|
||||||
asize -= frag
|
|
||||||
if ptrdata > frag {
|
|
||||||
ptrdata -= frag
|
|
||||||
} else {
|
|
||||||
ptrdata = 0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
pwsize := asize &^ (sys.PtrSize - 1)
|
bulkBarrierPreWrite(uintptr(dst), uintptr(src), pwsize)
|
||||||
if pwsize > ptrdata {
|
|
||||||
pwsize = ptrdata
|
|
||||||
}
|
|
||||||
bulkBarrierPreWrite(uintptr(adst), uintptr(asrc), pwsize)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
memmove(dst, src, size)
|
memmove(dst, src, size)
|
||||||
|
Loading…
Reference in New Issue
Block a user