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

builtin: add a map.reserve/1 method (#17052)

This commit is contained in:
MatejMagat305 2023-01-23 10:07:25 +01:00 committed by GitHub
parent 3a9355d898
commit 6d223b9a26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -425,6 +425,11 @@ fn (mut m map) expand() {
// the max_load_factor in an operation.
fn (mut m map) rehash() {
meta_bytes := sizeof(u32) * (m.even_index + 2 + m.extra_metas)
m.reserve(meta_bytes)
}
// reserve memory for the map meta data
pub fn (mut m map) reserve(meta_bytes u32) {
unsafe {
// TODO: use realloc_data here too
x := v_realloc(&u8(m.metas), int(meta_bytes))