]> Cypherpunks repositories - gostls13.git/commitdiff
pick off special one-byte case in copy. worth 2x in benchmarks (38ns->16ns).
authorRob Pike <r@golang.org>
Mon, 7 Dec 2009 19:28:02 +0000 (11:28 -0800)
committerRob Pike <r@golang.org>
Mon, 7 Dec 2009 19:28:02 +0000 (11:28 -0800)
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

index ba4be331b56bb1d1499eb8406ad721d93a391bd0..1d7a56e7ba8ef5568ec795664e8c233a83d2d336 100644 (file)
@@ -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);