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

map: faster get and exists

This commit is contained in:
ka-weihe 2020-05-09 12:42:01 +02:00 committed by GitHub
parent 1c8d2c21b5
commit 85763d0539
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -340,28 +340,32 @@ fn (m mut map) cached_rehash(old_cap u32) {
fn (m map) get3(key string, zero voidptr) voidptr { fn (m map) get3(key string, zero voidptr) voidptr {
mut index,mut meta := m.key_to_index(key) mut index,mut meta := m.key_to_index(key)
index,meta = m.meta_less(index, meta) for {
for meta == m.metas[index] { if meta == m.metas[index] {
kv_index := m.metas[index + 1] kv_index := m.metas[index + 1]
if fast_string_eq(key, m.key_values.keys[kv_index]) { if fast_string_eq(key, m.key_values.keys[kv_index]) {
return voidptr(m.key_values.values + kv_index * m.value_bytes) return voidptr(m.key_values.values + kv_index * m.value_bytes)
} }
}
index += 2 index += 2
meta += probe_inc meta += probe_inc
if meta > m.metas[index] { break }
} }
return zero return zero
} }
fn (m map) exists(key string) bool { fn (m map) exists(key string) bool {
mut index,mut meta := m.key_to_index(key) mut index,mut meta := m.key_to_index(key)
index,meta = m.meta_less(index, meta) for {
for meta == m.metas[index] { if meta == m.metas[index] {
kv_index := m.metas[index + 1] kv_index := m.metas[index + 1]
if fast_string_eq(key, m.key_values.keys[kv_index]) { if fast_string_eq(key, m.key_values.keys[kv_index]) {
return true return true
} }
}
index += 2 index += 2
meta += probe_inc meta += probe_inc
if meta > m.metas[index] { break }
} }
return false return false
} }