libgo: update to Go 1.11
[official-gcc.git] / libgo / go / internal / bytealg / compare_generic.go
blobbb488330e4af779bbe246bad631402ddae7ff26a
1 // Copyright 2018 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // +build ignore_for_gccgo
6 // +build !386,!amd64,!amd64p32,!s390x,!arm,!arm64,!ppc64,!ppc64le,!mips,!mipsle,!wasm
8 package bytealg
10 import _ "unsafe" // for go:linkname
12 func Compare(a, b []byte) int {
13 l := len(a)
14 if len(b) < l {
15 l = len(b)
17 if l == 0 || &a[0] == &b[0] {
18 goto samebytes
20 for i := 0; i < l; i++ {
21 c1, c2 := a[i], b[i]
22 if c1 < c2 {
23 return -1
25 if c1 > c2 {
26 return +1
29 samebytes:
30 if len(a) < len(b) {
31 return -1
33 if len(a) > len(b) {
34 return +1
36 return 0
39 //go:linkname bytes_Compare bytes.Compare
40 func bytes_Compare(a, b []byte) int {
41 l := len(a)
42 if len(b) < l {
43 l = len(b)
45 if l == 0 || &a[0] == &b[0] {
46 goto samebytes
48 for i := 0; i < l; i++ {
49 c1, c2 := a[i], b[i]
50 if c1 < c2 {
51 return -1
53 if c1 > c2 {
54 return +1
57 samebytes:
58 if len(a) < len(b) {
59 return -1
61 if len(a) > len(b) {
62 return +1
64 return 0
67 //go:linkname runtime_cmpstring runtime.cmpstring
68 func runtime_cmpstring(a, b string) int {
69 l := len(a)
70 if len(b) < l {
71 l = len(b)
73 for i := 0; i < l; i++ {
74 c1, c2 := a[i], b[i]
75 if c1 < c2 {
76 return -1
78 if c1 > c2 {
79 return +1
82 if len(a) < len(b) {
83 return -1
85 if len(a) > len(b) {
86 return +1
88 return 0