diff options
| author | Keith Randall <khr@golang.org> | 2024-11-04 15:52:02 -0800 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2024-11-17 21:09:09 +0000 |
| commit | 01e1e5c20438145df65a2fb79c77e3d5c3eb6831 (patch) | |
| tree | f9263f0f4832147260a8279d7135968c998fa92f /src/internal/runtime/maps | |
| parent | a867e5e5a6f0cc31ac9e4de8d9e25fd6be034325 (diff) | |
| download | go-01e1e5c20438145df65a2fb79c77e3d5c3eb6831.tar.xz | |
runtime/internal/maps: remove entryMask
It is easily recomputed as capacity-1.
This reduces a table from 40 to 32 bytes (on 64-bit archs).
That gets us down one sizeclass.
Change-Id: Icb74fb2de50baa18ca62052c7b2fe8e6af4c8837
Reviewed-on: https://go-review.googlesource.com/c/go/+/625198
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Keith Randall <khr@google.com>
Diffstat (limited to 'src/internal/runtime/maps')
| -rw-r--r-- | src/internal/runtime/maps/group.go | 4 | ||||
| -rw-r--r-- | src/internal/runtime/maps/table.go | 13 |
2 files changed, 7 insertions, 10 deletions
diff --git a/src/internal/runtime/maps/group.go b/src/internal/runtime/maps/group.go index aae667c8d8..59df1fb25a 100644 --- a/src/internal/runtime/maps/group.go +++ b/src/internal/runtime/maps/group.go @@ -218,9 +218,6 @@ type groupsReference struct { // length must be a power of two). This allows computing i%length // quickly using bitwise AND. lengthMask uint64 - - // entryMask is the total number of slots in the groups minus one. - entryMask uint64 } // newGroups allocates a new array of length groups. @@ -231,7 +228,6 @@ func newGroups(typ *abi.SwissMapType, length uint64) groupsReference { // TODO: make the length type the same throughout. data: newarray(typ.Group, int(length)), lengthMask: length - 1, - entryMask: (length * abi.SwissMapGroupSlots) - 1, } } diff --git a/src/internal/runtime/maps/table.go b/src/internal/runtime/maps/table.go index 847ff7fa6b..80745e9a72 100644 --- a/src/internal/runtime/maps/table.go +++ b/src/internal/runtime/maps/table.go @@ -803,7 +803,8 @@ func (it *Iter) Next() { // table for key selection if the table has grown. See comment // on grown below. - if it.entryIdx > it.tab.groups.entryMask { + entryMask := uint64(it.tab.capacity) - 1 + if it.entryIdx > entryMask { // Continue to next table. continue } @@ -819,7 +820,7 @@ func (it *Iter) Next() { // it is cheaper to check a single slot than do a full control // match. - entryIdx := (it.entryIdx + it.entryOffset) & it.tab.groups.entryMask + entryIdx := (it.entryIdx + it.entryOffset) & entryMask slotIdx := uintptr(entryIdx & (abi.SwissMapGroupSlots - 1)) if slotIdx == 0 || it.group.data == nil { // Only compute the group (a) when we switch @@ -864,7 +865,7 @@ func (it *Iter) Next() { return } -next: + next: it.entryIdx++ // Slow path: use a match on the control word to jump ahead to @@ -885,8 +886,8 @@ next: // double-check the control value. var groupMatch bitset - for it.entryIdx <= it.tab.groups.entryMask { - entryIdx := (it.entryIdx + it.entryOffset) & it.tab.groups.entryMask + for it.entryIdx <= entryMask { + entryIdx := (it.entryIdx + it.entryOffset) & entryMask slotIdx := uintptr(entryIdx & (abi.SwissMapGroupSlots - 1)) if slotIdx == 0 || it.group.data == nil { @@ -918,7 +919,7 @@ next: i := groupMatch.first() it.entryIdx += uint64(i - slotIdx) - if it.entryIdx > it.tab.groups.entryMask { + if it.entryIdx > entryMask { // Past the end of this table's iteration. continue } |
