Skip to content

Commit b730590

Browse files
deadprogramaykevl
authored andcommitted
runtime/all: add implementation of bytealg.CountString to complete #424
Signed-off-by: Ron Evans <[email protected]>
1 parent fb1a476 commit b730590

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/runtime/string.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,16 @@ func indexByteString(s string, c byte) int {
216216
}
217217
return -1
218218
}
219+
220+
// countString copies the implementation from
221+
// https://github.com/golang/go/blob/67f181bfd84dfd5942fe9a29d8a20c9ce5eb2fea/src/internal/bytealg/count_generic.go#L1
222+
//go:linkname countString internal/bytealg.CountString
223+
func countString(s string, c byte) int {
224+
n := 0
225+
for i := 0; i < len(s); i++ {
226+
if s[i] == c {
227+
n++
228+
}
229+
}
230+
return n
231+
}

0 commit comments

Comments
 (0)