* cp-tree.h (build_noexcept_spec, add_exception_specifier): Adjust
[official-gcc.git] / libgo / go / bytes / indexbyte.c
blobb248108e404a5dec4e19a730d50a272bbeafdff5
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. */
7 #include <stddef.h>
9 #include "runtime.h"
10 #include "array.h"
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));
20 intgo
21 IndexByte (struct __go_open_array s, char b)
23 char *p;
25 p = __builtin_memchr (s.__values, b, s.__count);
26 if (p == NULL)
27 return -1;
28 return p - (char *) s.__values;
31 /* Comparison. */
33 _Bool Equal (struct __go_open_array a, struct __go_open_array b)
34 __asm__ (GOSYM_PREFIX "bytes.Equal")
35 __attribute__ ((no_split_stack));
37 _Bool
38 Equal (struct __go_open_array a, struct __go_open_array b)
40 if (a.__count != b.__count)
41 return 0;
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));
49 intgo
50 Compare (struct __go_open_array a, struct __go_open_array b)
52 intgo len;
54 len = a.__count;
55 if (len > b.__count)
56 len = b.__count;
57 if (len > 0)
59 intgo ret;
61 ret = __builtin_memcmp (a.__values, b.__values, len);
62 if (ret < 0)
63 return -1;
64 else if (ret > 0)
65 return 1;
67 if (a.__count < b.__count)
68 return -1;
69 else if (a.__count > b.__count)
70 return 1;
71 else
72 return 0;