1 /* indexbyte.c -- implement bytes.IndexByte for Go.
3 Copyright 2009 The Go Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file. */
12 /* This is in C so that the compiler can optimize it appropriately.
13 We deliberately don't split the stack in case it does call the
14 library function, which shouldn't need much stack space. */
16 intgo
IndexByte (struct __go_open_array
, char)
17 __asm__ (GOSYM_PREFIX
"bytes.IndexByte")
18 __attribute__ ((no_split_stack
));
21 IndexByte (struct __go_open_array s
, char b
)
25 p
= __builtin_memchr (s
.__values
, b
, s
.__count
);
28 return p
- (char *) s
.__values
;
33 _Bool
Equal (struct __go_open_array a
, struct __go_open_array b
)
34 __asm__ (GOSYM_PREFIX
"bytes.Equal")
35 __attribute__ ((no_split_stack
));
38 Equal (struct __go_open_array a
, struct __go_open_array b
)
40 if (a
.__count
!= b
.__count
)
42 return __builtin_memcmp (a
.__values
, b
.__values
, a
.__count
) == 0;
45 intgo
Compare (struct __go_open_array a
, struct __go_open_array b
)
46 __asm__ (GOSYM_PREFIX
"bytes.Compare")
47 __attribute__ ((no_split_stack
));
50 Compare (struct __go_open_array a
, struct __go_open_array b
)
61 ret
= __builtin_memcmp (a
.__values
, b
.__values
, len
);
67 if (a
.__count
< b
.__count
)
69 else if (a
.__count
> b
.__count
)