]> Cypherpunks repositories - gostls13.git/commitdiff
internal/runtime/maps: avoid passing unused key return
authorMichael Pratt <mpratt@google.com>
Wed, 21 Aug 2024 20:17:16 +0000 (16:17 -0400)
committerGopher Robot <gobot@golang.org>
Mon, 28 Oct 2024 21:25:16 +0000 (21:25 +0000)
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 <mpratt@google.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/internal/runtime/maps/map.go
src/internal/runtime/maps/table.go

index ad6edd65bf4a4e09dc6090cde9050f1fdc7e1c88..a4fa07635ae254a73243f585bb94cb4e9521c981 100644 (file)
@@ -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,
index 86e5dce10d393afc2ad90ad2605cddc88138dc52..ac200133c90b113efca3c29dd0185f7eb7cb97e7 100644 (file)
@@ -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.
 //