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

strings,builder: reduce V cgen and parser memory consumption, fix strings.Builder leak (#12342)

This commit is contained in:
Delyan Angelov
2021-10-31 12:58:55 +02:00
committed by GitHub
parent ce9f26c589
commit 6937074e7a
6 changed files with 72 additions and 15 deletions

View File

@ -11,7 +11,9 @@ pub type Builder = []byte
// new_builder returns a new string builder, with an initial capacity of `initial_size`
pub fn new_builder(initial_size int) Builder {
return Builder([]byte{cap: initial_size})
mut res := Builder([]byte{cap: initial_size})
unsafe { res.flags.set(.noslices) }
return res
}
// write_ptr writes `len` bytes provided byteptr to the accumulated buffer
@ -161,9 +163,8 @@ pub fn (mut b Builder) str() string {
pub fn (mut b Builder) free() {
if b.data != 0 {
unsafe { free(b.data) }
mut pd := &b.data
unsafe {
(*pd) = voidptr(0)
b.data = voidptr(0)
}
}
}