From b7305900594629b5d965f8badb90073d062afcc4 Mon Sep 17 00:00:00 2001 From: Ron Evans Date: Mon, 7 Oct 2019 18:24:51 +0200 Subject: [PATCH] runtime/all: add implementation of bytealg.CountString to complete #424 Signed-off-by: Ron Evans --- src/runtime/string.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/runtime/string.go b/src/runtime/string.go index 30736d30..cf6d0af6 100644 --- a/src/runtime/string.go +++ b/src/runtime/string.go @@ -216,3 +216,16 @@ func indexByteString(s string, c byte) int { } return -1 } + +// countString copies the implementation from +// https://github.com/golang/go/blob/67f181bfd84dfd5942fe9a29d8a20c9ce5eb2fea/src/internal/bytealg/count_generic.go#L1 +//go:linkname countString internal/bytealg.CountString +func countString(s string, c byte) int { + n := 0 + for i := 0; i < len(s); i++ { + if s[i] == c { + n++ + } + } + return n +}