builtin: optimize []rune.string()

pull/11240/head
Alexander Medvednikov 2021-08-19 06:58:53 +03:00
parent 0cbc77d881
commit 26b77515b9
1 changed files with 7 additions and 2 deletions

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. // Use of this source code is governed by an MIT license that can be found in the LICENSE file.
module builtin module builtin
import strings
// This was never working correctly, the issue is now // This was never working correctly, the issue is now
// fixed however the type checks in checker need to be // fixed however the type checks in checker need to be
// updated. if you uncomment it you will see the issue // 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 // string converts a rune array to a string
[manualfree]
pub fn (ra []rune) string() string { pub fn (ra []rune) string() string {
mut res := '' mut sb := strings.new_builder(ra.len)
for r in ra { for r in ra {
res += r.str() sb.write_string(r.str())
} }
res := sb.str()
unsafe { sb.free() }
return res return res
} }