From b750f1d1bb8bc0cc971910787c39ac42655d3f7f Mon Sep 17 00:00:00 2001 From: Joe Conigliaro Date: Thu, 12 Mar 2020 22:19:13 +1100 Subject: [PATCH] compiler: prerequisite changes for upcoming map update --- vlib/builtin/map.v | 8 ++++++++ vlib/compiler/cgen.v | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/vlib/builtin/map.v b/vlib/builtin/map.v index 948a18d517..950657aad0 100644 --- a/vlib/builtin/map.v +++ b/vlib/builtin/map.v @@ -59,6 +59,14 @@ mut: value voidptr } +// Dynamic array with very low growth factor +struct DenseArray { +mut: + data &KeyValue + cap u32 + size u32 +} + fn new_map(n, value_bytes int) map { probe_hash_bytes := sizeof(u32) * init_capicity key_value_bytes := sizeof(KeyValue) * init_capicity diff --git a/vlib/compiler/cgen.v b/vlib/compiler/cgen.v index 37975eeb0d..bf9022445a 100644 --- a/vlib/compiler/cgen.v +++ b/vlib/compiler/cgen.v @@ -401,7 +401,7 @@ fn (v &V) type_definitions() string { mut types := []Type // structs that need to be sorted mut builtin_types := []Type // builtin types // builtin types need to be on top - builtins := ['string', 'array', 'map', 'Option'] + builtins := ['string', 'array', 'KeyValue', 'DenseArray', 'map', 'Option'] for builtin in builtins { typ := v.table.typesmap[builtin] builtin_types << typ