strings: remove allocations in Split(s, "")

BenchmarkSplit1     77984460     24131380  -69.06%

R=golang-dev, rsc, minux.ma, dave, extemporalgenome
CC=golang-dev
https://golang.org/cl/7458043
This commit is contained in:
Ewan Chou 2013-03-06 15:21:19 -05:00 committed by Russ Cox
parent 64eec93225
commit 4f43201e51
2 changed files with 23 additions and 1 deletions

View file

@ -26,7 +26,11 @@ func explode(s string, n int) []string {
i, cur := 0, 0
for ; i+1 < n; i++ {
ch, size = utf8.DecodeRuneInString(s[cur:])
a[i] = string(ch)
if ch == utf8.RuneError {
a[i] = string(utf8.RuneError)
} else {
a[i] = s[cur : cur+size]
}
cur += size
}
// add the rest, if there is any