mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-05 19:43:44 +00:00
compiler,runtime: use the size hint when creating a new map
It defaults to hint/8 number of buckets. This number may be tuned in the future.
This commit is contained in:
committed by
Ron Evans
parent
17c42810d0
commit
55fc7b904a
+10
-4
@@ -60,14 +60,20 @@ func hashmapTopHash(hash uint32) uint8 {
|
||||
}
|
||||
|
||||
// Create a new hashmap with the given keySize and valueSize.
|
||||
func hashmapMake(keySize, valueSize uint8) *hashmap {
|
||||
func hashmapMake(keySize, valueSize uint8, sizeHint uintptr) *hashmap {
|
||||
numBuckets := sizeHint / 8
|
||||
bucketBits := uint8(0)
|
||||
for numBuckets != 0 {
|
||||
numBuckets /= 2
|
||||
bucketBits++
|
||||
}
|
||||
bucketBufSize := unsafe.Sizeof(hashmapBucket{}) + uintptr(keySize)*8 + uintptr(valueSize)*8
|
||||
bucket := alloc(bucketBufSize)
|
||||
buckets := alloc(bucketBufSize * (1 << bucketBits))
|
||||
return &hashmap{
|
||||
buckets: bucket,
|
||||
buckets: buckets,
|
||||
keySize: keySize,
|
||||
valueSize: valueSize,
|
||||
bucketBits: 0,
|
||||
bucketBits: bucketBits,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user