github.com/llvm-mirror/llgo@v0.0.0-20190322182713-bf6f0a60fce1/third_party/gofrontend/libgo/go/strings/indexbyte.c (about) 1 /* indexbyte.c -- implement strings.IndexByte for Go. 2 3 Copyright 2013 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. */ 6 7 #include <stddef.h> 8 9 #include "runtime.h" 10 #include "go-string.h" 11 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. */ 15 16 intgo IndexByte (String, char) 17 __asm__ (GOSYM_PREFIX "strings.IndexByte") 18 __attribute__ ((no_split_stack)); 19 20 intgo 21 IndexByte (String s, char b) 22 { 23 const char *p; 24 25 p = __builtin_memchr ((const char *) s.str, b, s.len); 26 if (p == NULL) 27 return -1; 28 return p - (const char *) s.str; 29 }