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:

committed by
Alexander Medvednikov

parent
ad99b82930
commit
931b71c428
@@ -1015,11 +1015,9 @@ pub fn (s string) repeat(count int) string {
|
|||||||
if count <= 1 {
|
if count <= 1 {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
ret := malloc(s.len * count + count)
|
ret := malloc(s.len * count + 1)
|
||||||
C.strcpy(ret, s.str)
|
for _ in 0..count {
|
||||||
for count > 1 {
|
|
||||||
C.strcat(ret, s.str)
|
C.strcat(ret, s.str)
|
||||||
count--
|
|
||||||
}
|
}
|
||||||
return string(ret)
|
return string(ret)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user