1
2
3
4
5
6
7 package bytealg
8
9 import _ "unsafe"
10
11 func Compare(a, b []byte) int {
12 l := len(a)
13 if len(b) < l {
14 l = len(b)
15 }
16 if l == 0 || &a[0] == &b[0] {
17 goto samebytes
18 }
19 for i := 0; i < l; i++ {
20 c1, c2 := a[i], b[i]
21 if c1 < c2 {
22 return -1
23 }
24 if c1 > c2 {
25 return +1
26 }
27 }
28 samebytes:
29 if len(a) < len(b) {
30 return -1
31 }
32 if len(a) > len(b) {
33 return +1
34 }
35 return 0
36 }
37
38
39 func runtime_cmpstring(a, b string) int {
40 l := len(a)
41 if len(b) < l {
42 l = len(b)
43 }
44 for i := 0; i < l; i++ {
45 c1, c2 := a[i], b[i]
46 if c1 < c2 {
47 return -1
48 }
49 if c1 > c2 {
50 return +1
51 }
52 }
53 if len(a) < len(b) {
54 return -1
55 }
56 if len(a) > len(b) {
57 return +1
58 }
59 return 0
60 }
61
View as plain text