1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

string: improve repeat()

This commit is contained in:
Alvydas Vitkauskas 2019-09-27 15:49:09 +03:00 committed by Alexander Medvednikov
parent ad99b82930
commit 931b71c428

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)
}