From 6d223b9a26c86223506cc34f2c7acd24cfc3a08c Mon Sep 17 00:00:00 2001 From: MatejMagat305 <61238240+MatejMagat305@users.noreply.github.com> Date: Mon, 23 Jan 2023 10:07:25 +0100 Subject: [PATCH] builtin: add a map.reserve/1 method (#17052) --- vlib/builtin/map.v | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/vlib/builtin/map.v b/vlib/builtin/map.v index 7b96d124af..71ad5275af 100644 --- a/vlib/builtin/map.v +++ b/vlib/builtin/map.v @@ -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))