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

strings: simplify repeat()

This commit is contained in:
Alexander Medvednikov 2019-09-25 22:08:07 +03:00
parent 3fbfc5fbd4
commit 4c898ab6b3

View File

@ -4,11 +4,7 @@ pub fn repeat(c byte, n int) string {
if n <= 0 {
return ''
}
//mut arr := malloc(n + 1)
mut arr := [byte(0)].repeat(n + 1)
for i := 0; i < n; i++ {
arr[i] = c
}
mut arr := [c].repeat(n + 1)
arr[n] = `\0`
return string(arr, n)
}