aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2009-12-07 11:28:02 -0800
committerRob Pike <r@golang.org>2009-12-07 11:28:02 -0800
commit20c1ec263a8910ae1b794cb017f59e73997a9296 (patch)
treee037e0913cdf47f06644edf063afd7ad90af1c23
parent80e17d67976b29c4de6173d858efbe0955648404 (diff)
downloadgo-20c1ec263a8910ae1b794cb017f59e73997a9296.tar.gz
go-20c1ec263a8910ae1b794cb017f59e73997a9296.zip
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
-rw-r--r--src/pkg/runtime/slice.c6
1 files changed, 5 insertions, 1 deletions
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);