Skip to content

Commit

Permalink
Add an assert to the compiler for map sizes.
Browse files Browse the repository at this point in the history
We require that they are a power of 2, otherwise we have to fall
back to a slow % operator, instead of &.
  • Loading branch information
AWoloszyn committed Feb 27, 2018
1 parent 780eb05 commit b320ea9
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions gapil/compiler/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ import (
// If we end up with lots of insertions/deletions, this will prevent linear search

func (c *C) defineMapType(t *semantic.Map) {

if ((minMapSize & (minMapSize - 1)) != 0) ||
((mapGrowMultiplier & (mapGrowMultiplier - 1)) != 0) {
fail("Map size must be a power of 2")
}

mapPtrTy := c.T.target[t].(codegen.Pointer)
mapStrTy := mapPtrTy.Element.(*codegen.Struct)
keyTy := c.T.Target(t.KeyType)
Expand Down

0 comments on commit b320ea9

Please sign in to comment.