From 26b77515b947c45faf826c3e6019f014f255d0b6 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 19 Aug 2021 06:58:53 +0300 Subject: [PATCH] builtin: optimize []rune.string() --- vlib/builtin/rune.v | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/vlib/builtin/rune.v b/vlib/builtin/rune.v index 0f78a11412..bc2a9ba7e4 100644 --- a/vlib/builtin/rune.v +++ b/vlib/builtin/rune.v @@ -2,6 +2,8 @@ // Use of this source code is governed by an MIT license that can be found in the LICENSE file. module builtin +import strings + // This was never working correctly, the issue is now // fixed however the type checks in checker need to be // updated. if you uncomment it you will see the issue @@ -29,11 +31,14 @@ pub fn (c rune) str() string { } // string converts a rune array to a string +[manualfree] pub fn (ra []rune) string() string { - mut res := '' + mut sb := strings.new_builder(ra.len) for r in ra { - res += r.str() + sb.write_string(r.str()) } + res := sb.str() + unsafe { sb.free() } return res }