]> Cypherpunks repositories - gostls13.git/commitdiff
internal/runtime/maps: use matchEmptyOrDeleted instead of matchEmpty
authorkhr@golang.org <khr@golang.org>
Thu, 31 Oct 2024 17:10:08 +0000 (10:10 -0700)
committerKeith Randall <khr@golang.org>
Fri, 1 Nov 2024 20:10:31 +0000 (20:10 +0000)
It's a bit more efficient.

Change-Id: If813a597516c41fdac6f60e586641d0ee1cde025
Reviewed-on: https://go-review.googlesource.com/c/go/+/623818
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Carlos Amedee <carlos@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/runtime_fast32_swiss.go
src/internal/runtime/maps/runtime_fast64_swiss.go
src/internal/runtime/maps/runtime_faststr_swiss.go
src/internal/runtime/maps/table.go

index 262f20f5cb5792ceafb3e631c89ccf366360d02f..46439602470d528dfcbaf52170f670e2fd2c956d 100644 (file)
@@ -554,9 +554,10 @@ func (m *Map) putSlotSmall(typ *abi.SwissMapType, hash uintptr, key unsafe.Point
                match = match.removeFirst()
        }
 
-       // No need to look for deleted slots, small maps can't have them (see
-       // deleteSmall).
-       match = g.ctrls().matchEmpty()
+       // There can't be deleted slots, small maps can't have them
+       // (see deleteSmall). Use matchEmptyOrDeleted as it is a bit
+       // more efficient than matchEmpty.
+       match = g.ctrls().matchEmptyOrDeleted()
        if match == 0 {
                fatal("small map with no empty slot (concurrent map writes?)")
        }
index 33de96b0dc8a99c32e30fa1f571a38d8896cc2f2..a61257d5de9b3e71e94d4544460775365726d66f 100644 (file)
@@ -160,9 +160,10 @@ func (m *Map) putSlotSmallFast32(typ *abi.SwissMapType, hash uintptr, key uint32
                match = match.removeFirst()
        }
 
-       // No need to look for deleted slots, small maps can't have them (see
-       // deleteSmall).
-       match = g.ctrls().matchEmpty()
+       // There can't be deleted slots, small maps can't have them
+       // (see deleteSmall). Use matchEmptyOrDeleted as it is a bit
+       // more efficient than matchEmpty.
+       match = g.ctrls().matchEmptyOrDeleted()
        if match == 0 {
                fatal("small map with no empty slot (concurrent map writes?)")
        }
index 09a76922137247fa906fbc09145484191d500264..85e9b7a392dca3c25601d5ff1ce68f31572691fc 100644 (file)
@@ -159,9 +159,10 @@ func (m *Map) putSlotSmallFast64(typ *abi.SwissMapType, hash uintptr, key uint64
                match = match.removeFirst()
        }
 
-       // No need to look for deleted slots, small maps can't have them (see
-       // deleteSmall).
-       match = g.ctrls().matchEmpty()
+       // There can't be deleted slots, small maps can't have them
+       // (see deleteSmall). Use matchEmptyOrDeleted as it is a bit
+       // more efficient than matchEmpty.
+       match = g.ctrls().matchEmptyOrDeleted()
        if match == 0 {
                fatal("small map with no empty slot (concurrent map writes?)")
        }
@@ -336,9 +337,10 @@ func (m *Map) putSlotSmallFastPtr(typ *abi.SwissMapType, hash uintptr, key unsaf
                match = match.removeFirst()
        }
 
-       // No need to look for deleted slots, small maps can't have them (see
-       // deleteSmall).
-       match = g.ctrls().matchEmpty()
+       // There can't be deleted slots, small maps can't have them
+       // (see deleteSmall). Use matchEmptyOrDeleted as it is a bit
+       // more efficient than matchEmpty.
+       match = g.ctrls().matchEmptyOrDeleted()
        if match == 0 {
                fatal("small map with no empty slot (concurrent map writes?)")
        }
index a103839cb6df30f6446f54cbf0a1e498a48db8da..b7f88ab1ef86c6773900d91995e21927b86d1d0e 100644 (file)
@@ -176,9 +176,10 @@ func (m *Map) putSlotSmallFastStr(typ *abi.SwissMapType, hash uintptr, key strin
                match = match.removeFirst()
        }
 
-       // No need to look for deleted slots, small maps can't have them (see
-       // deleteSmall).
-       match = g.ctrls().matchEmpty()
+       // There can't be deleted slots, small maps can't have them
+       // (see deleteSmall). Use matchEmptyOrDeleted as it is a bit
+       // more efficient than matchEmpty.
+       match = g.ctrls().matchEmptyOrDeleted()
        if match == 0 {
                fatal("small map with no empty slot (concurrent map writes?)")
        }
index d5ec24e7a6e7dfcb9847bdf8a50984fa1a86d4d7..8eb4a38c07ac374face4436aa38157e6d0050c75 100644 (file)
@@ -381,6 +381,8 @@ func (t *table) PutSlot(typ *abi.SwissMapType, m *Map, hash uintptr, key unsafe.
 // Requires that the entry does not exist in the table, and that the table has
 // room for another element without rehashing.
 //
+// Requires that there are no deleted entries in the table.
+//
 // Never returns nil.
 func (t *table) uncheckedPutSlot(typ *abi.SwissMapType, hash uintptr, key unsafe.Pointer) unsafe.Pointer {
        if t.growthLeft == 0 {
@@ -395,7 +397,7 @@ func (t *table) uncheckedPutSlot(typ *abi.SwissMapType, hash uintptr, key unsafe
        for ; ; seq = seq.next() {
                g := t.groups.group(typ, seq.offset)
 
-               match := g.ctrls().matchEmpty()
+               match := g.ctrls().matchEmptyOrDeleted()
                if match != 0 {
                        i := match.first()
 
@@ -414,9 +416,7 @@ func (t *table) uncheckedPutSlot(typ *abi.SwissMapType, hash uintptr, key unsafe
                                slotElem = emem
                        }
 
-                       if g.ctrls().get(i) == ctrlEmpty {
-                               t.growthLeft--
-                       }
+                       t.growthLeft--
                        g.ctrls().set(i, ctrl(h2(hash)))
                        return slotElem
                }