Skip to content

Commit cb4c226

Browse files
author
Fayaz
committed
Merge branch 'master' of https://github.com/p32929/go_easy
2 parents 3ab0696 + bfc2095 commit cb4c226

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/internal/runtime/maps/map.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -439,15 +439,10 @@ func (m *Map) getWithKeySmall(typ *abi.SwissMapType, hash uintptr, key unsafe.Po
439439
data: m.dirPtr,
440440
}
441441

442-
h2 := uint8(h2(hash))
443-
ctrls := *g.ctrls()
442+
match := g.ctrls().matchH2(h2(hash))
444443

445-
for i := uintptr(0); i < abi.SwissMapGroupSlots; i++ {
446-
c := uint8(ctrls)
447-
ctrls >>= 8
448-
if c != h2 {
449-
continue
450-
}
444+
for match != 0 {
445+
i := match.first()
451446

452447
slotKey := g.key(typ, i)
453448
if typ.IndirectKey() {
@@ -461,8 +456,12 @@ func (m *Map) getWithKeySmall(typ *abi.SwissMapType, hash uintptr, key unsafe.Po
461456
}
462457
return slotKey, slotElem, true
463458
}
459+
460+
match = match.removeFirst()
464461
}
465462

463+
// No match here means key is not in the map.
464+
// (A single group means no need to probe or check for empty).
466465
return nil, nil, false
467466
}
468467

src/runtime/map_benchmark_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,9 +1182,12 @@ func BenchmarkMapSmallAccessHit(b *testing.B) {
11821182
b.Run("Key=int32/Elem=int32", smallBenchSizes(benchmarkMapAccessHit[int32, int32]))
11831183
b.Run("Key=int64/Elem=int64", smallBenchSizes(benchmarkMapAccessHit[int64, int64]))
11841184
b.Run("Key=string/Elem=string", smallBenchSizes(benchmarkMapAccessHit[string, string]))
1185+
b.Run("Key=smallType/Elem=int32", smallBenchSizes(benchmarkMapAccessHit[smallType, int32]))
11851186
}
1187+
11861188
func BenchmarkMapSmallAccessMiss(b *testing.B) {
11871189
b.Run("Key=int32/Elem=int32", smallBenchSizes(benchmarkMapAccessMiss[int32, int32]))
11881190
b.Run("Key=int64/Elem=int64", smallBenchSizes(benchmarkMapAccessMiss[int64, int64]))
11891191
b.Run("Key=string/Elem=string", smallBenchSizes(benchmarkMapAccessMiss[string, string]))
1192+
b.Run("Key=smallType/Elem=int32", smallBenchSizes(benchmarkMapAccessMiss[smallType, int32]))
11901193
}

0 commit comments

Comments
 (0)