From f3abb9e68205c22528071a625e4ab0bcf08c93d5 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Thu, 10 Oct 2019 20:02:32 +0300 Subject: [PATCH] fix 'v -debug examples/hello_world.v' --- compiler/module_header.v | 8 ++++---- vlib/builtin/hashmap.v | 8 +++----- vlib/builtin/hashmap_test.v | 1 - 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/compiler/module_header.v b/compiler/module_header.v index 86edf0ac56..f3d3c063e2 100644 --- a/compiler/module_header.v +++ b/compiler/module_header.v @@ -44,7 +44,7 @@ fn (f &Fn) v_definition() string { if i == 0 && f.is_method { // skip the receiver continue } - typ := v_type_str(arg.typ) + typ := v_type_str(arg.typ).replace('*', '&') if arg.name == '' { sb.write(typ) } else { @@ -56,7 +56,7 @@ fn (f &Fn) v_definition() string { } sb.write(')') if f.typ != 'void' { - typ := v_type_str(f.typ) + typ := v_type_str(f.typ).replace('*', '&') sb.write(' ') sb.write(typ) sb.writeln(' ') @@ -170,7 +170,7 @@ fn (v &V) generate_vh() { if field.access_mod == .public { continue } - field_type := v_type_str(field.typ) + field_type := v_type_str(field.typ).replace('*', '&') file.writeln('\t$field.name $field_type') } //file.writeln('pub:') @@ -179,7 +179,7 @@ fn (v &V) generate_vh() { if field.access_mod == .private { continue } - field_type := v_type_str(field.typ) + field_type := v_type_str(field.typ).replace('*', '&') public_str += '\t$field.name $field_type\n' //file.writeln('\t$field.name $field_type') } diff --git a/vlib/builtin/hashmap.v b/vlib/builtin/hashmap.v index de1009d8a4..6a9bd9afa5 100644 --- a/vlib/builtin/hashmap.v +++ b/vlib/builtin/hashmap.v @@ -14,8 +14,6 @@ module builtin the performance gains are basically non-existent. */ -import math - struct hashmap { cap int keys []string @@ -52,7 +50,7 @@ fn new_hashmap(planned_nr_items int) hashmap { } fn (m mut hashmap) set(key string, val int) { - hash := int(math.abs(key.hash())) + mut hash := int(b_fabs( key.hash() )) idx := hash % m.cap if m.table[idx].key.len != 0 { //println('\nset() idx=$idx key="$key" hash="$hash" val=$val') @@ -69,7 +67,7 @@ fn (m mut hashmap) set(key string, val int) { } fn (m mut hashmap) get(key string) int { - hash := int(math.abs(key.hash())) + hash := int(b_fabs( key.hash() )) idx := hash % m.cap mut e := &m.table[idx] for e.next != 0 { // todo unsafe { @@ -81,4 +79,4 @@ fn (m mut hashmap) get(key string) int { return e.val } - +[inline] fn b_fabs(v int) f64 { return if v < 0 { -v } else { v } } diff --git a/vlib/builtin/hashmap_test.v b/vlib/builtin/hashmap_test.v index 4bb588342d..c45b2f3165 100644 --- a/vlib/builtin/hashmap_test.v +++ b/vlib/builtin/hashmap_test.v @@ -1,5 +1,4 @@ import rand -import strings fn test_random_strings() { mut m := new_hashmap(1000)