From: khr@golang.org Date: Thu, 31 Oct 2024 17:10:08 +0000 (-0700) Subject: internal/runtime/maps: use matchEmptyOrDeleted instead of matchEmpty X-Git-Tag: go1.24rc1~507 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=378c48e6c7c9f62c80b4d627302fda978ece2a1d;p=gostls13.git internal/runtime/maps: use matchEmptyOrDeleted instead of matchEmpty It's a bit more efficient. Change-Id: If813a597516c41fdac6f60e586641d0ee1cde025 Reviewed-on: https://go-review.googlesource.com/c/go/+/623818 Reviewed-by: Michael Pratt Reviewed-by: Carlos Amedee LUCI-TryBot-Result: Go LUCI --- diff --git a/src/internal/runtime/maps/map.go b/src/internal/runtime/maps/map.go index 262f20f5cb..4643960247 100644 --- a/src/internal/runtime/maps/map.go +++ b/src/internal/runtime/maps/map.go @@ -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?)") } diff --git a/src/internal/runtime/maps/runtime_fast32_swiss.go b/src/internal/runtime/maps/runtime_fast32_swiss.go index 33de96b0dc..a61257d5de 100644 --- a/src/internal/runtime/maps/runtime_fast32_swiss.go +++ b/src/internal/runtime/maps/runtime_fast32_swiss.go @@ -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?)") } diff --git a/src/internal/runtime/maps/runtime_fast64_swiss.go b/src/internal/runtime/maps/runtime_fast64_swiss.go index 09a7692213..85e9b7a392 100644 --- a/src/internal/runtime/maps/runtime_fast64_swiss.go +++ b/src/internal/runtime/maps/runtime_fast64_swiss.go @@ -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?)") } diff --git a/src/internal/runtime/maps/runtime_faststr_swiss.go b/src/internal/runtime/maps/runtime_faststr_swiss.go index a103839cb6..b7f88ab1ef 100644 --- a/src/internal/runtime/maps/runtime_faststr_swiss.go +++ b/src/internal/runtime/maps/runtime_faststr_swiss.go @@ -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?)") } diff --git a/src/internal/runtime/maps/table.go b/src/internal/runtime/maps/table.go index d5ec24e7a6..8eb4a38c07 100644 --- a/src/internal/runtime/maps/table.go +++ b/src/internal/runtime/maps/table.go @@ -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 }