aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2015-08-24 20:58:19 -0700
committerKeith Randall <khr@golang.org>2015-08-29 02:43:57 +0000
commit805e56ef474a8abfc4ec4159bea0c1fb584e67ed (patch)
tree566141074bcca0bd500773508bc10a2661b0b181
parentd93f3b5e31c2d95c6237d72b089576a50dacea79 (diff)
downloadgo-805e56ef474a8abfc4ec4159bea0c1fb584e67ed.tar.xz
runtime: short-circuit bytes.Compare if src and dst are the same slice
Should only matter on ppc64 and ppc64le. Fixes #11336 Change-Id: Id4b0ac28b573648e1aa98e87bf010f00d006b146 Reviewed-on: https://go-review.googlesource.com/13901 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Dave Cheney <dave@cheney.net>
-rw-r--r--src/runtime/noasm.go4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/runtime/noasm.go b/src/runtime/noasm.go
index 9a6dbeec3d..218e121bf7 100644
--- a/src/runtime/noasm.go
+++ b/src/runtime/noasm.go
@@ -39,6 +39,9 @@ func bytes_Compare(s1, s2 []byte) int {
if len(s2) < l {
l = len(s2)
}
+ if l == 0 || &s1[0] == &s2[0] {
+ goto samebytes
+ }
for i := 0; i < l; i++ {
c1, c2 := s1[i], s2[i]
if c1 < c2 {
@@ -48,6 +51,7 @@ func bytes_Compare(s1, s2 []byte) int {
return +1
}
}
+samebytes:
if len(s1) < len(s2) {
return -1
}