string: improve repeat()
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)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue