string.repeat: re-write without a libc function call

pull/2141/head
Alexander Medvednikov 2019-09-28 02:51:42 +03:00
parent 1821dac795
commit a5391c8882
1 changed files with 5 additions and 3 deletions

View File

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