From 20c1ec263a8910ae1b794cb017f59e73997a9296 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Mon, 7 Dec 2009 11:28:02 -0800 Subject: [PATCH] pick off special one-byte case in copy. worth 2x in benchmarks (38ns->16ns). the one-item case could be generalized easily with no cost. worth considering. R=rsc CC=golang-dev, cw https://golang.org/cl/167044 --- src/pkg/runtime/slice.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/pkg/runtime/slice.c b/src/pkg/runtime/slice.c index ba4be331b5..1d7a56e7ba 100644 --- a/src/pkg/runtime/slice.c +++ b/src/pkg/runtime/slice.c @@ -208,7 +208,11 @@ runtime·slicecopy(Slice to, Slice fm, uintptr width, int32 ret) if(to.len < ret) ret = to.len; - memmove(to.array, fm.array, ret*width); + if(ret == 1 && width == 1) { // common case worth about 2x to do here + *to.array = *fm.array; // known to be a byte pointer + } else { + memmove(to.array, fm.array, ret*width); + } out: FLUSH(&ret); -- 2.50.0