compiler: support comma-ok in map lookup

This commit is contained in:
Ayke van Laethem
2018-10-20 17:54:16 +02:00
parent da89464a63
commit 7c2a6169b0
5 changed files with 33 additions and 15 deletions
+7 -6
View File
@@ -122,7 +122,7 @@ func hashmapSet(m *hashmap, key unsafe.Pointer, value unsafe.Pointer, hash uint3
// Get the value of a specified key, or zero the value if not found.
//go:nobounds
func hashmapGet(m *hashmap, key unsafe.Pointer, value unsafe.Pointer, hash uint32, keyEqual func(x, y unsafe.Pointer, n uintptr) bool) {
func hashmapGet(m *hashmap, key unsafe.Pointer, value unsafe.Pointer, hash uint32, keyEqual func(x, y unsafe.Pointer, n uintptr) bool) bool {
numBuckets := uintptr(1) << m.bucketBits
bucketNumber := (uintptr(hash) & (numBuckets - 1))
bucketSize := unsafe.Sizeof(hashmapBucket{}) + uintptr(m.keySize)*8 + uintptr(m.valueSize)*8
@@ -147,7 +147,7 @@ func hashmapGet(m *hashmap, key unsafe.Pointer, value unsafe.Pointer, hash uint3
if keyEqual(key, slotKey, uintptr(m.keySize)) {
// Found the key, copy it.
memcpy(value, slotValue, uintptr(m.valueSize))
return
return true
}
}
}
@@ -156,6 +156,7 @@ func hashmapGet(m *hashmap, key unsafe.Pointer, value unsafe.Pointer, hash uint3
// Did not find the key.
memzero(value, uintptr(m.valueSize))
return false
}
// Delete a given key from the map. No-op when the key does not exist in the
@@ -239,9 +240,9 @@ func hashmapBinarySet(m *hashmap, key, value unsafe.Pointer) {
hashmapSet(m, key, value, hash, memequal)
}
func hashmapBinaryGet(m *hashmap, key, value unsafe.Pointer) {
func hashmapBinaryGet(m *hashmap, key, value unsafe.Pointer) bool {
hash := hashmapHash(key, uintptr(m.keySize))
hashmapGet(m, key, value, hash, memequal)
return hashmapGet(m, key, value, hash, memequal)
}
func hashmapBinaryDelete(m *hashmap, key unsafe.Pointer) {
@@ -265,9 +266,9 @@ func hashmapStringSet(m *hashmap, key string, value unsafe.Pointer) {
hashmapSet(m, unsafe.Pointer(&key), value, hash, hashmapStringEqual)
}
func hashmapStringGet(m *hashmap, key string, value unsafe.Pointer) {
func hashmapStringGet(m *hashmap, key string, value unsafe.Pointer) bool {
hash := hashmapStringHash(key)
hashmapGet(m, unsafe.Pointer(&key), value, hash, hashmapStringEqual)
return hashmapGet(m, unsafe.Pointer(&key), value, hash, hashmapStringEqual)
}
func hashmapStringDelete(m *hashmap, key string) {