mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-18 11:33:59 +00:00
+16
-3
@@ -281,13 +281,26 @@ func hashmapInsertIntoNewBucket(m *hashmap, key, value unsafe.Pointer, tophash u
|
|||||||
}
|
}
|
||||||
|
|
||||||
func hashmapGrow(m *hashmap) {
|
func hashmapGrow(m *hashmap) {
|
||||||
|
// allocate our new buckets twice as big
|
||||||
|
n := hashmapCopy(m, m.bucketBits+1)
|
||||||
|
*m = n
|
||||||
|
}
|
||||||
|
|
||||||
|
//go:linkname hashmapClone maps.clone
|
||||||
|
func hashmapClone(intf _interface) _interface {
|
||||||
|
typ, val := decomposeInterface(intf)
|
||||||
|
m := (*hashmap)(val)
|
||||||
|
n := hashmapCopy(m, m.bucketBits)
|
||||||
|
return composeInterface(typ, unsafe.Pointer(&n))
|
||||||
|
}
|
||||||
|
|
||||||
|
func hashmapCopy(m *hashmap, sizeBits uint8) hashmap {
|
||||||
// clone map as empty
|
// clone map as empty
|
||||||
n := *m
|
n := *m
|
||||||
n.count = 0
|
n.count = 0
|
||||||
n.seed = uintptr(fastrand())
|
n.seed = uintptr(fastrand())
|
||||||
|
|
||||||
// allocate our new buckets twice as big
|
n.bucketBits = sizeBits
|
||||||
n.bucketBits = m.bucketBits + 1
|
|
||||||
numBuckets := uintptr(1) << n.bucketBits
|
numBuckets := uintptr(1) << n.bucketBits
|
||||||
bucketBufSize := hashmapBucketSize(m)
|
bucketBufSize := hashmapBucketSize(m)
|
||||||
n.buckets = alloc(bucketBufSize*numBuckets, nil)
|
n.buckets = alloc(bucketBufSize*numBuckets, nil)
|
||||||
@@ -303,7 +316,7 @@ func hashmapGrow(m *hashmap) {
|
|||||||
hashmapSet(&n, key, value, h)
|
hashmapSet(&n, key, value, h)
|
||||||
}
|
}
|
||||||
|
|
||||||
*m = n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the value of a specified key, or zero the value if not found.
|
// Get the value of a specified key, or zero the value if not found.
|
||||||
|
|||||||
Reference in New Issue
Block a user