From: Rob Pike Date: Mon, 7 Dec 2009 19:28:02 +0000 (-0800) Subject: pick off special one-byte case in copy. worth 2x in benchmarks (38ns->16ns). X-Git-Tag: weekly.2009-12-07~6 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=20c1ec263a8910ae1b794cb017f59e73997a9296;p=gostls13.git 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 --- 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);