From f033d988b1926215f59aa1eee37c05e59adbac02 Mon Sep 17 00:00:00 2001 From: Evan Shaw Date: Tue, 27 Aug 2013 09:21:08 +1000 Subject: [PATCH] bytes, strings: use copy in Repeat R=golang-dev, dave, bradfitz, adg CC=golang-dev https://golang.org/cl/13249043 --- src/pkg/bytes/bytes.go | 5 +---- src/pkg/strings/strings.go | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/pkg/bytes/bytes.go b/src/pkg/bytes/bytes.go index 405b10a1db..01a5d9ae4e 100644 --- a/src/pkg/bytes/bytes.go +++ b/src/pkg/bytes/bytes.go @@ -375,10 +375,7 @@ func Repeat(b []byte, count int) []byte { nb := make([]byte, len(b)*count) bp := 0 for i := 0; i < count; i++ { - for j := 0; j < len(b); j++ { - nb[bp] = b[j] - bp++ - } + bp += copy(nb[bp:], b) } return nb } diff --git a/src/pkg/strings/strings.go b/src/pkg/strings/strings.go index 4d33f1ecd7..5d46211d84 100644 --- a/src/pkg/strings/strings.go +++ b/src/pkg/strings/strings.go @@ -425,10 +425,7 @@ func Repeat(s string, count int) string { b := make([]byte, len(s)*count) bp := 0 for i := 0; i < count; i++ { - for j := 0; j < len(s); j++ { - b[bp] = s[j] - bp++ - } + bp += copy(b[bp:], s) } return string(b) } -- 2.48.1