diff --git a/vlib/builtin/string.v b/vlib/builtin/string.v index 75543bff68..7c4450313f 100644 --- a/vlib/builtin/string.v +++ b/vlib/builtin/string.v @@ -725,15 +725,9 @@ fn (s string) + (a string) string { str: unsafe { malloc_noscan(new_len + 1) } len: new_len } - for j in 0 .. s.len { - unsafe { - res.str[j] = s.str[j] - } - } - for j in 0 .. a.len { - unsafe { - res.str[s.len + j] = a.str[j] - } + unsafe { + vmemcpy(res.str, s.str, s.len) + vmemcpy(res.str + s.len, a.str, a.len) } unsafe { res.str[new_len] = 0 // V strings are not null terminated, but just in case @@ -2077,10 +2071,8 @@ pub fn (s string) repeat(count int) string { } mut ret := unsafe { malloc_noscan(s.len * count + 1) } for i in 0 .. count { - for j in 0 .. s.len { - unsafe { - ret[i * s.len + j] = s[j] - } + unsafe { + vmemcpy(ret + i * s.len, s.str, s.len) } } new_len := s.len * count