...

Source file src/internal/bytealg/indexbyte_generic.go

Documentation: internal/bytealg

     1  // Copyright 2018 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Avoid IndexByte and IndexByteString on Plan 9 because it uses
     6  // SSE instructions on x86 machines, and those are classified as
     7  // floating point instructions, which are illegal in a note handler.
     8  
     9  //go:build !386 && (!amd64 || plan9) && !s390x && !arm && !arm64 && !loong64 && !ppc64 && !ppc64le && !mips && !mipsle && !mips64 && !mips64le && !riscv64 && !wasm
    10  
    11  package bytealg
    12  
    13  func IndexByte(b []byte, c byte) int {
    14  	for i, x := range b {
    15  		if x == c {
    16  			return i
    17  		}
    18  	}
    19  	return -1
    20  }
    21  
    22  func IndexByteString(s string, c byte) int {
    23  	for i := 0; i < len(s); i++ {
    24  		if s[i] == c {
    25  			return i
    26  		}
    27  	}
    28  	return -1
    29  }
    30  

View as plain text