github.com/tardisgo/tardisgo@v0.0.0-20161119180838-e0dd9a7e46b5/goroot/haxe/go1.4/src/bytes/bytes_decl_haxe.go (about) 1 // Copyright 2014 Elliott Stoneham and The tardisgo Authors 2 // Use of this source code is governed by an MIT-style 3 // license that can be found in the LICENSE file. 4 5 // Some code below: 6 // Copyright 2010 The Go Authors. All rights reserved. 7 // Use of this source code is governed by a BSD-style 8 // license that can be found in the LICENSE file. 9 10 // +build haxe 11 12 // Package bytes contains runtime functions for the Go "bytes" standard library package when used by TARDIS Go 13 package bytes 14 15 func init() { // to stop the functions being removed by dead-code-elimination 16 //if false { 17 // IndexByte([]byte{}, 0) 18 // Equal([]byte{}, []byte{}) 19 // Compare([]byte{}, []byte{}) 20 //} 21 } 22 23 //****go:noescape 24 25 // IndexByte returns the index of the first instance of c in s, or -1 if c is not present in s. 26 func IndexByte(s []byte, c byte) int { 27 for i := range s { 28 if s[i] == c { 29 return i 30 } 31 } 32 return -1 33 } // asm_$GOARCH.s 34 35 //****go:noescape 36 37 // Equal returns a boolean reporting whether a == b. 38 // A nil argument is equivalent to an empty slice. 39 func Equal(a, b []byte) bool { 40 if a == nil { 41 if b == nil { 42 return true 43 } 44 return len(b) == 0 45 } 46 if b == nil { 47 return len(a) == 0 48 } 49 if len(a) != len(b) { 50 return false 51 } 52 for i := range a { 53 if a[i] != b[i] { 54 return false 55 } 56 } 57 return true 58 } // asm_arm.s or ../runtime/asm_{386,amd64}.s 59 60 //****go:noescape 61 62 // Compare returns an integer comparing two byte slices lexicographically. 63 // The result will be 0 if a==b, -1 if a < b, and +1 if a > b. 64 // A nil argument is equivalent to an empty slice. 65 func Compare(a, b []byte) int { 66 if a == nil { 67 if b == nil { 68 return 0 69 } 70 if len(b) == 0 { 71 return 0 72 } 73 return -1 74 } 75 if b == nil { 76 if len(a) == 0 { 77 return 0 78 } 79 return 1 80 } 81 i := 0 82 for (i < len(a)) && (i < len(b)) { 83 if a[i] < b[i] { 84 return -1 85 } 86 if a[i] > b[i] { 87 return +1 88 } 89 i++ 90 } 91 if len(a) == len(b) { 92 return 0 93 } 94 if len(a) < len(b) { 95 return -1 96 } 97 return +1 98 } // ../runtime/noasm_arm.goc or ../runtime/asm_{386,amd64}.s