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

builtin: optimize []rune.string()

This commit is contained in:
Alexander Medvednikov 2021-08-19 06:58:53 +03:00
parent 0cbc77d881
commit 26b77515b9

View File

@ -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
}