mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
prealloc: skip frees for now
This commit is contained in:
parent
fae601fe39
commit
ab3c1f2a08
@ -438,6 +438,9 @@ pub fn (a array) reverse() array {
|
||||
// pub fn (a []int) free() {
|
||||
[unsafe_fn]
|
||||
pub fn (a &array) free() {
|
||||
$if prealloc {
|
||||
return
|
||||
}
|
||||
// if a.is_slice {
|
||||
// return
|
||||
// }
|
||||
|
@ -165,13 +165,23 @@ TODO
|
||||
*/
|
||||
}
|
||||
|
||||
//#include <malloc/malloc.h>
|
||||
//fn malloc_size(b byteptr) int
|
||||
|
||||
[unsafe_fn]
|
||||
pub fn v_realloc(b byteptr, n u32) byteptr {
|
||||
ptr := C.realloc(b, n)
|
||||
if ptr == 0 {
|
||||
panic('realloc($n) failed')
|
||||
$if prealloc {
|
||||
new_ptr := malloc(int(n))
|
||||
size := 0 //malloc_size(b)
|
||||
C.memcpy(new_ptr, b, size)
|
||||
return new_ptr
|
||||
} $else {
|
||||
ptr := C.realloc(b, n)
|
||||
if ptr == 0 {
|
||||
panic('realloc($n) failed')
|
||||
}
|
||||
return ptr
|
||||
}
|
||||
return ptr
|
||||
}
|
||||
|
||||
[unsafe_fn]
|
||||
@ -191,6 +201,9 @@ pub fn vcalloc(n int) byteptr {
|
||||
|
||||
[unsafe_fn]
|
||||
pub fn free(ptr voidptr) {
|
||||
$if prealloc {
|
||||
return
|
||||
}
|
||||
C.free(ptr)
|
||||
}
|
||||
|
||||
@ -203,6 +216,9 @@ pub fn memdup(src voidptr, sz int) voidptr {
|
||||
}
|
||||
|
||||
fn v_ptr_free(ptr voidptr) {
|
||||
$if prealloc {
|
||||
return
|
||||
}
|
||||
C.free(ptr)
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ fn new_dense_array(value_bytes int) DenseArray {
|
||||
fn (mut d DenseArray) push(key string, value voidptr) u32 {
|
||||
if d.cap == d.len {
|
||||
d.cap += d.cap >> 3
|
||||
d.keys = &string(v_realloc(d.keys, sizeof(string) * d.cap))
|
||||
d.keys = &string(v_realloc(byteptr(d.keys), sizeof(string) * d.cap))
|
||||
d.values = v_realloc(d.values, u32(d.value_bytes) * d.cap)
|
||||
}
|
||||
push_index := d.len
|
||||
|
@ -1170,6 +1170,9 @@ pub fn (u ustring) at(idx int) string {
|
||||
}
|
||||
|
||||
fn (u &ustring) free() {
|
||||
$if prealloc {
|
||||
return
|
||||
}
|
||||
u.runes.free()
|
||||
}
|
||||
|
||||
@ -1194,6 +1197,9 @@ pub fn (c byte) is_letter() bool {
|
||||
}
|
||||
|
||||
pub fn (s &string) free() {
|
||||
$if prealloc {
|
||||
return
|
||||
}
|
||||
if s.is_lit == -98761234 {
|
||||
C.printf('double string.free() detected\n')
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user