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

builtin: reduce allocations in rune.bytes()

This commit is contained in:
Delyan Angelov
2022-01-11 14:41:01 +02:00
parent cb684b5c64
commit 8acd84d04a
2 changed files with 21 additions and 10 deletions

View File

@@ -54,8 +54,11 @@ pub fn (c rune) repeat(count int) string {
return res.repeat(count)
}
[manualfree]
pub fn (c rune) bytes() []byte {
return c.str().bytes()
mut res := []byte{cap: 5}
res.len = unsafe { utf32_decode_to_buffer(u32(c), &byte(res.data)) }
return res
}
pub fn (c rune) length_in_bytes() int {