diff options
author | Josh Bleecher Snyder <josharian@gmail.com> | 2017-11-12 22:11:51 -0800 |
---|---|---|
committer | Josh Bleecher Snyder <josharian@gmail.com> | 2018-02-15 15:05:15 +0000 |
commit | 3658299f449e63026caf08a02eba855aab6755b6 (patch) | |
tree | ab757055305075fa46944cc7a13069525008b969 /src/runtime/mbarrier.go | |
parent | bf9f1c15035ab9bb695a9a3504e465a1896b4b8c (diff) | |
download | go-3658299f449e63026caf08a02eba855aab6755b6.tar.gz go-3658299f449e63026caf08a02eba855aab6755b6.zip |
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>
Diffstat (limited to 'src/runtime/mbarrier.go')
-rw-r--r-- | src/runtime/mbarrier.go | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/runtime/mbarrier.go b/src/runtime/mbarrier.go index c071728900..c446db93d2 100644 --- a/src/runtime/mbarrier.go +++ b/src/runtime/mbarrier.go @@ -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 |