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