string: improve repeat()

pull/2132/head
Alvydas Vitkauskas 2019-09-27 15:49:09 +03:00 committed by Alexander Medvednikov
parent ad99b82930
commit 931b71c428
1 changed files with 2 additions and 4 deletions

View File

@ -1015,11 +1015,9 @@ pub fn (s string) repeat(count int) string {
if count <= 1 {
return s
}
ret := malloc(s.len * count + count)
C.strcpy(ret, s.str)
for count > 1 {
ret := malloc(s.len * count + 1)
for _ in 0..count {
C.strcat(ret, s.str)
count--
}
return string(ret)
}