mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
all: use v_realloc
This commit is contained in:
parent
867929e0b4
commit
649821be4c
@ -102,7 +102,7 @@ fn (mut a array) ensure_cap(required int) {
|
||||
a.data = vcalloc(cap * a.element_size)
|
||||
}
|
||||
else {
|
||||
a.data = C.realloc(a.data, cap * a.element_size)
|
||||
a.data = v_realloc(a.data, u32(cap * a.element_size))
|
||||
}
|
||||
a.cap = cap
|
||||
}
|
||||
|
@ -166,7 +166,7 @@ TODO
|
||||
}
|
||||
|
||||
[unsafe_fn]
|
||||
pub fn v_realloc(b byteptr, n int) byteptr {
|
||||
pub fn v_realloc(b byteptr, n u32) byteptr {
|
||||
ptr := C.realloc(b, n)
|
||||
if ptr == 0 {
|
||||
panic('realloc($n) failed')
|
||||
|
@ -122,8 +122,8 @@ 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(C.realloc(d.keys, sizeof(string) * d.cap))
|
||||
d.values = C.realloc(d.values, u32(d.value_bytes) * d.cap)
|
||||
d.keys = &string(v_realloc(d.keys, sizeof(string) * d.cap))
|
||||
d.values = v_realloc(d.values, u32(d.value_bytes) * d.cap)
|
||||
}
|
||||
push_index := d.len
|
||||
d.keys[push_index] = key
|
||||
@ -168,8 +168,8 @@ fn (mut d DenseArray) zeros_to_end() {
|
||||
d.deletes = 0
|
||||
d.len = count
|
||||
d.cap = if count < 8 { u32(8) } else { count }
|
||||
d.keys = &string(C.realloc(d.keys, sizeof(string) * d.cap))
|
||||
d.values = C.realloc(d.values, u32(d.value_bytes) * d.cap)
|
||||
d.keys = &string(v_realloc(d.keys, sizeof(string) * d.cap))
|
||||
d.values = v_realloc(d.values, u32(d.value_bytes) * d.cap)
|
||||
}
|
||||
|
||||
pub struct map {
|
||||
@ -267,7 +267,7 @@ fn (mut m map) ensure_extra_metas(probe_count u32) {
|
||||
m.extra_metas += extra_metas_inc
|
||||
mem_size := (m.cap + 2 + m.extra_metas)
|
||||
unsafe {
|
||||
m.metas = &u32(C.realloc(m.metas, sizeof(u32) * mem_size))
|
||||
m.metas = &u32(v_realloc(m.metas, sizeof(u32) * mem_size))
|
||||
C.memset(m.metas + mem_size - extra_metas_inc, 0, sizeof(u32) * extra_metas_inc)
|
||||
}
|
||||
// Should almost never happen
|
||||
@ -328,7 +328,7 @@ fn (mut m map) expand() {
|
||||
// the max_load_factor in an operation.
|
||||
fn (mut m map) rehash() {
|
||||
meta_bytes := sizeof(u32) * (m.cap + 2 + m.extra_metas)
|
||||
m.metas = &u32(C.realloc(m.metas, meta_bytes))
|
||||
m.metas = &u32(v_realloc(m.metas, meta_bytes))
|
||||
C.memset(m.metas, 0, meta_bytes)
|
||||
for i := u32(0); i < m.key_values.len; i++ {
|
||||
if m.key_values.keys[i].str == 0 {
|
||||
|
@ -280,7 +280,7 @@ pub fn (mut ws Client) write(payload byteptr, payload_len int, code OPCode) int
|
||||
goto free_data
|
||||
return -1
|
||||
}
|
||||
unsafe
|
||||
unsafe
|
||||
{
|
||||
C.memcpy(fbdata, header.data, header_len)
|
||||
C.memcpy(fbdata + header_len, payload, payload_len)
|
||||
@ -385,7 +385,7 @@ pub fn (mut ws Client) read() int {
|
||||
frame_size = u64(header_len) + payload_len
|
||||
if frame_size > initial_buffer {
|
||||
l.d('reallocating: ${frame_size}')
|
||||
data = C.realloc(data, frame_size)
|
||||
data = v_realloc(data, frame_size)
|
||||
}
|
||||
} else if frame.payload_len == u64(127) && bytes_read == u64(extended_payload64_end_byte) {
|
||||
header_len += 8 // TODO Not sure...
|
||||
@ -409,7 +409,7 @@ pub fn (mut ws Client) read() int {
|
||||
frame_size = u64(header_len) + payload_len
|
||||
if frame_size > initial_buffer {
|
||||
l.d('reallocating: ${frame_size}')
|
||||
data = C.realloc(data, frame_size)
|
||||
data = v_realloc(data, frame_size)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user