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