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

cgen: fix map_get: use zero value if the key was not found

This commit is contained in:
Alexander Medvednikov
2020-03-23 20:02:09 +01:00
parent 80676cf44f
commit 2e29e09b1b
2 changed files with 27 additions and 0 deletions

View File

@ -345,6 +345,25 @@ fn (m map) get2(key string) voidptr {
return voidptr(0)
}
fn (m map) get3(key string, zero voidptr) voidptr {
mut index,mut meta := m.key_to_index(key)
index,meta = meta_less(m.metas, index, meta)
for meta == m.metas[index] {
kv_index := m.metas[index + 1]
if key == m.key_values.data[kv_index].key {
out := malloc(m.value_bytes)
C.memcpy(out, m.key_values.data[kv_index].value, m.value_bytes)
return out
}
index += 2
meta += probe_inc
}
out := malloc(m.value_bytes)
C.memcpy(out, zero, m.value_bytes)
return out
//return voidptr(0)
}
fn (m map) exists(key string) bool {
if m.value_bytes == 0 {
return false