runtime: only implement CountString for required platforms
Этот коммит содержится в:
родитель
405c0263b0
коммит
efafda1d32
4 изменённых файлов: 25 добавлений и 13 удалений
|
@ -216,16 +216,3 @@ func indexByteString(s string, c byte) int {
|
||||||
}
|
}
|
||||||
return -1
|
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
|
|
||||||
}
|
|
||||||
|
|
23
src/runtime/string_count.go
Обычный файл
23
src/runtime/string_count.go
Обычный файл
|
@ -0,0 +1,23 @@
|
||||||
|
// +build amd64 arm,go1.13 arm64 ppc64le ppc64 s390x
|
||||||
|
|
||||||
|
package runtime
|
||||||
|
|
||||||
|
// This file implements the string counting functions used by the strings
|
||||||
|
// package, for example. It must be reimplemented here as a replacement for the
|
||||||
|
// Go stdlib asm implementations, but only when the asm implementations are used
|
||||||
|
// (this varies by Go version).
|
||||||
|
// Track this file for updates:
|
||||||
|
// https://github.com/golang/go/blob/master/src/internal/bytealg/count_native.go
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
1
testdata/stdlib.go
предоставленный
1
testdata/stdlib.go
предоставленный
|
@ -18,4 +18,5 @@ func main() {
|
||||||
|
|
||||||
// package strings
|
// package strings
|
||||||
fmt.Println("strings.IndexByte:", strings.IndexByte("asdf", 'd'))
|
fmt.Println("strings.IndexByte:", strings.IndexByte("asdf", 'd'))
|
||||||
|
fmt.Println("strings.Replace:", strings.Replace("An example string", " ", "-", -1))
|
||||||
}
|
}
|
||||||
|
|
1
testdata/stdlib.txt
предоставленный
1
testdata/stdlib.txt
предоставленный
|
@ -3,3 +3,4 @@ stdout: 1
|
||||||
stderr: 2
|
stderr: 2
|
||||||
pseudorandom number: 1298498081
|
pseudorandom number: 1298498081
|
||||||
strings.IndexByte: 2
|
strings.IndexByte: 2
|
||||||
|
strings.Replace: An-example-string
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче