mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-07 12:33:42 +00:00
compiler: support comma-ok in map lookup
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user