...

Source file src/internal/bytealg/count_native.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  //go:build amd64 || arm || arm64 || ppc64le || ppc64 || riscv64 || s390x
     6  
     7  package bytealg
     8  
     9  //go:noescape
    10  func Count(b []byte, c byte) int
    11  
    12  //go:noescape
    13  func CountString(s string, c byte) int
    14  
    15  // A backup implementation to use by assembly.
    16  func countGeneric(b []byte, c byte) int {
    17  	n := 0
    18  	for _, x := range b {
    19  		if x == c {
    20  			n++
    21  		}
    22  	}
    23  	return n
    24  }
    25  func countGenericString(s string, c byte) int {
    26  	n := 0
    27  	for i := 0; i < len(s); i++ {
    28  		if s[i] == c {
    29  			n++
    30  		}
    31  	}
    32  	return n
    33  }
    34  

View as plain text