From a5391c88828edd1f9047b89c1592dd2ce8ca063f Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sat, 28 Sep 2019 02:51:42 +0300 Subject: [PATCH] string.repeat: re-write without a libc function call --- vlib/builtin/string.v | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/vlib/builtin/string.v b/vlib/builtin/string.v index 02061b7d0a..b756a61321 100644 --- a/vlib/builtin/string.v +++ b/vlib/builtin/string.v @@ -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) }