fix 'v -debug examples/hello_world.v'

pull/2293/head
Delyan Angelov 2019-10-10 20:02:32 +03:00 committed by Alexander Medvednikov
parent 1b79964827
commit f3abb9e682
3 changed files with 7 additions and 10 deletions

View File

@ -44,7 +44,7 @@ fn (f &Fn) v_definition() string {
if i == 0 && f.is_method { // skip the receiver if i == 0 && f.is_method { // skip the receiver
continue continue
} }
typ := v_type_str(arg.typ) typ := v_type_str(arg.typ).replace('*', '&')
if arg.name == '' { if arg.name == '' {
sb.write(typ) sb.write(typ)
} else { } else {
@ -56,7 +56,7 @@ fn (f &Fn) v_definition() string {
} }
sb.write(')') sb.write(')')
if f.typ != 'void' { if f.typ != 'void' {
typ := v_type_str(f.typ) typ := v_type_str(f.typ).replace('*', '&')
sb.write(' ') sb.write(' ')
sb.write(typ) sb.write(typ)
sb.writeln(' ') sb.writeln(' ')
@ -170,7 +170,7 @@ fn (v &V) generate_vh() {
if field.access_mod == .public { if field.access_mod == .public {
continue 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('\t$field.name $field_type')
} }
//file.writeln('pub:') //file.writeln('pub:')
@ -179,7 +179,7 @@ fn (v &V) generate_vh() {
if field.access_mod == .private { if field.access_mod == .private {
continue continue
} }
field_type := v_type_str(field.typ) field_type := v_type_str(field.typ).replace('*', '&')
public_str += '\t$field.name $field_type\n' public_str += '\t$field.name $field_type\n'
//file.writeln('\t$field.name $field_type') //file.writeln('\t$field.name $field_type')
} }

View File

@ -14,8 +14,6 @@ module builtin
the performance gains are basically non-existent. the performance gains are basically non-existent.
*/ */
import math
struct hashmap { struct hashmap {
cap int cap int
keys []string keys []string
@ -52,7 +50,7 @@ fn new_hashmap(planned_nr_items int) hashmap {
} }
fn (m mut hashmap) set(key string, val int) { 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 idx := hash % m.cap
if m.table[idx].key.len != 0 { if m.table[idx].key.len != 0 {
//println('\nset() idx=$idx key="$key" hash="$hash" val=$val') //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 { fn (m mut hashmap) get(key string) int {
hash := int(math.abs(key.hash())) hash := int(b_fabs( key.hash() ))
idx := hash % m.cap idx := hash % m.cap
mut e := &m.table[idx] mut e := &m.table[idx]
for e.next != 0 { // todo unsafe { for e.next != 0 { // todo unsafe {
@ -81,4 +79,4 @@ fn (m mut hashmap) get(key string) int {
return e.val return e.val
} }
[inline] fn b_fabs(v int) f64 { return if v < 0 { -v } else { v } }

View File

@ -1,5 +1,4 @@
import rand import rand
import strings
fn test_random_strings() { fn test_random_strings() {
mut m := new_hashmap(1000) mut m := new_hashmap(1000)