From: Michael Pratt Date: Wed, 21 Aug 2024 20:17:16 +0000 (-0400) Subject: internal/runtime/maps: avoid passing unused key return X-Git-Tag: go1.24rc1~563 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=775837f51f03245bcba333094b4b3742f8fbfca3;p=gostls13.git internal/runtime/maps: avoid passing unused key return For #54766. Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest-swissmap Change-Id: Idee1e021e3cef8f0c031e8f06efbcf6e88918d8a Reviewed-on: https://go-review.googlesource.com/c/go/+/622376 Auto-Submit: Michael Pratt Reviewed-by: Keith Randall Reviewed-by: Keith Randall LUCI-TryBot-Result: Go LUCI --- diff --git a/src/internal/runtime/maps/map.go b/src/internal/runtime/maps/map.go index ad6edd65bf..a4fa07635a 100644 --- a/src/internal/runtime/maps/map.go +++ b/src/internal/runtime/maps/map.go @@ -360,8 +360,7 @@ func (m *Map) Used() uint64 { // Get performs a lookup of the key that key points to. It returns a pointer to // the element, or false if the key doesn't exist. func (m *Map) Get(key unsafe.Pointer) (unsafe.Pointer, bool) { - _, elem, ok := m.getWithKey(key) - return elem, ok + return m.getWithoutKey(key) } func (m *Map) getWithKey(key unsafe.Pointer) (unsafe.Pointer, unsafe.Pointer, bool) { @@ -375,6 +374,18 @@ func (m *Map) getWithKey(key unsafe.Pointer) (unsafe.Pointer, unsafe.Pointer, bo return m.directoryAt(idx).getWithKey(hash, key) } +func (m *Map) getWithoutKey(key unsafe.Pointer) (unsafe.Pointer, bool) { + hash := m.typ.Hasher(key, m.seed) + + if m.dirLen == 0 { + _, elem, ok := m.getWithKeySmall(hash, key) + return elem, ok + } + + idx := m.directoryIndex(hash) + return m.directoryAt(idx).getWithoutKey(hash, key) +} + func (m *Map) getWithKeySmall(hash uintptr, key unsafe.Pointer) (unsafe.Pointer, unsafe.Pointer, bool) { g := groupReference{ typ: m.typ, diff --git a/src/internal/runtime/maps/table.go b/src/internal/runtime/maps/table.go index 86e5dce10d..ac200133c9 100644 --- a/src/internal/runtime/maps/table.go +++ b/src/internal/runtime/maps/table.go @@ -231,6 +231,32 @@ func (t *table) getWithKey(hash uintptr, key unsafe.Pointer) (unsafe.Pointer, un } } +func (t *table) getWithoutKey(hash uintptr, key unsafe.Pointer) (unsafe.Pointer, bool) { + seq := makeProbeSeq(h1(hash), t.groups.lengthMask) + for ; ; seq = seq.next() { + g := t.groups.group(seq.offset) + + match := g.ctrls().matchH2(h2(hash)) + + for match != 0 { + i := match.first() + + slotKey := g.key(i) + if t.typ.Key.Equal(key, slotKey) { + return g.elem(i), true + } + match = match.removeFirst() + } + + match = g.ctrls().matchEmpty() + if match != 0 { + // Finding an empty slot means we've reached the end of + // the probe sequence. + return nil, false + } + } +} + // PutSlot returns a pointer to the element slot where an inserted element // should be written, and ok if it returned a valid slot. //