mirror of
https://github.com/golang/go
synced 2024-11-19 12:54:45 -07:00
runtime: short-circuit typedslicecopy when dstp == srcp
If copying from a slice to itself, skip the write barriers and actual memory copies. This happens in practice in code like this snippet from the trim pass in the compiler, when k ends up being 0: copy(s.Values[k:], s.Values[:m]) Change-Id: Ie6924acfd56151f874d87f1d7f1f74320b4c4f10 Reviewed-on: https://go-review.googlesource.com/94023 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
parent
bf9f1c1503
commit
3658299f44
@ -254,6 +254,10 @@ func typedslicecopy(typ *_type, dst, src slice) int {
|
||||
cgoCheckSliceCopy(typ, dst, src, n)
|
||||
}
|
||||
|
||||
if dstp == srcp {
|
||||
return n
|
||||
}
|
||||
|
||||
// Note: No point in checking typ.kind&kindNoPointers here:
|
||||
// compiler only emits calls to typedslicecopy for types with pointers,
|
||||
// and growslice and reflect_typedslicecopy check for pointers
|
||||
|
Loading…
Reference in New Issue
Block a user