From: Josh Bleecher Snyder Date: Mon, 17 Jul 2017 03:37:27 +0000 (-1000) Subject: runtime: use integer math for hashmap overLoadFactor X-Git-Tag: go1.10beta1~1587 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=733567a1860956e87daa1a2fa46d58fc44b896cc;p=gostls13.git runtime: use integer math for hashmap overLoadFactor Change-Id: I92cf39a05e738a03d956779d7a1ab1ef8074b2ab Reviewed-on: https://go-review.googlesource.com/54655 Run-TryBot: Josh Bleecher Snyder TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- diff --git a/src/runtime/hashmap.go b/src/runtime/hashmap.go index 87d0d26cfa..64ec84474e 100644 --- a/src/runtime/hashmap.go +++ b/src/runtime/hashmap.go @@ -64,8 +64,10 @@ const ( bucketCntBits = 3 bucketCnt = 1 << bucketCntBits - // Maximum average load of a bucket that triggers growth. - loadFactor = 6.5 + // Maximum average load of a bucket that triggers growth is 6.5. + // Represent as loadFactorNum/loadFactDen, to allow integer math. + loadFactorNum = 13 + loadFactorDen = 2 // Maximum key or value size to keep inline (instead of mallocing per element). // Must fit in a uint8. @@ -984,8 +986,7 @@ func hashGrow(t *maptype, h *hmap) { // overLoadFactor reports whether count items placed in 1<= bucketCnt && float32(count) >= loadFactor*float32((uint64(1)<= bucketCnt && uint64(count) >= loadFactorNum*((uint64(1)<