internal/bytealg: reimplement bytealg in pure Go

Previously, we implemented individual bytealg functions via linknaming, and had to update them every once in a while when we hit linker errors.
Instead, this change reimplements the bytealg package in pure Go.
If something is missing, it will cause a compiler error rather than a linker error.
This is easier to test and maintain.
This commit is contained in:
Jaden Weiss
2020-04-07 17:09:30 -04:00
committed by Ayke
parent 38fc340802
commit 473644d918
6 changed files with 130 additions and 48 deletions
-12
View File
@@ -204,15 +204,3 @@ func decodeUTF8(s string, index uintptr) (rune, uintptr) {
return 0xfffd, 1
}
}
// indexByteString returns the index of the first instance of c in s, or -1 if c
// is not present in s.
//go:linkname indexByteString internal/bytealg.IndexByteString
func indexByteString(s string, c byte) int {
for i := 0; i < len(s); i++ {
if s[i] == c {
return i
}
}
return -1
}