diff options
| author | Evan Shaw <chickencha@gmail.com> | 2011-03-29 01:27:38 -0400 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2011-03-29 01:27:38 -0400 |
| commit | 47f4ae1a78cb09999f57b34a38913047d5d99a53 (patch) | |
| tree | 4333c7c5c1bd5714dc4b50d359d94199e3dc0aea /src/pkg/bytes/bytes.go | |
| parent | ac74f14b6b94d05e9db6a535b7e7b57fdbf09007 (diff) | |
| download | go-47f4ae1a78cb09999f57b34a38913047d5d99a53.tar.xz | |
bytes, strings: simplify Join
R=gri, rsc
CC=golang-dev
https://golang.org/cl/4300044
Diffstat (limited to 'src/pkg/bytes/bytes.go')
| -rw-r--r-- | src/pkg/bytes/bytes.go | 18 |
1 files changed, 4 insertions, 14 deletions
diff --git a/src/pkg/bytes/bytes.go b/src/pkg/bytes/bytes.go index bfe2ef39db..c12a135738 100644 --- a/src/pkg/bytes/bytes.go +++ b/src/pkg/bytes/bytes.go @@ -293,20 +293,10 @@ func Join(a [][]byte, sep []byte) []byte { } b := make([]byte, n) - bp := 0 - for i := 0; i < len(a); i++ { - s := a[i] - for j := 0; j < len(s); j++ { - b[bp] = s[j] - bp++ - } - if i+1 < len(a) { - s = sep - for j := 0; j < len(s); j++ { - b[bp] = s[j] - bp++ - } - } + bp := copy(b, a[0]) + for _, s := range a[1:] { + bp += copy(b[bp:], sep) + bp += copy(b[bp:], s) } return b } |
