Skip to content

Commit 4bd7465

Browse files
Thomas StrombergThomas Stromberg
authored andcommitted
getShard cleanup
1 parent 8554555 commit 4bd7465

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

s3fifo.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -359,12 +359,12 @@ func (s *shard[K, V]) putGhostEntry(e *ghostEntry[K]) {
359359
s.freeGhostEntries = e
360360
}
361361

362-
// getShard returns the shard for a given key using type-optimized hashing.
362+
// shard returns the shard for a given key using type-optimized hashing.
363363
// Uses bitwise AND with shardMask for fast modulo (numShards must be power of 2).
364364
// Fast paths for int, int64, and string keys avoid the type switch overhead entirely.
365365
//
366366
//go:nosplit
367-
func (c *s3fifo[K, V]) getShard(key K) *shard[K, V] {
367+
func (c *s3fifo[K, V]) shard(key K) *shard[K, V] {
368368
// Fast path for int keys (most common case in benchmarks).
369369
// The keyIsInt flag is set once at construction, so this branch is predictable.
370370
if c.keyIsInt {
@@ -404,7 +404,7 @@ func (c *s3fifo[K, V]) shardIndexSlow(key K) uint64 {
404404
// get retrieves a value from the cache.
405405
// On hit, increments frequency counter (used during eviction).
406406
func (c *s3fifo[K, V]) get(key K) (V, bool) {
407-
return c.getShard(key).get(key)
407+
return c.shard(key).get(key)
408408
}
409409

410410
func (s *shard[K, V]) get(key K) (V, bool) {
@@ -435,7 +435,7 @@ func (s *shard[K, V]) get(key K) (V, bool) {
435435
// getOrSet retrieves a value or sets it if not found, in a single operation.
436436
// Returns the value and true if found, or sets the value and returns false.
437437
func (c *s3fifo[K, V]) getOrSet(key K, value V, expiryNano int64) (V, bool) {
438-
return c.getShard(key).getOrSet(key, value, expiryNano)
438+
return c.shard(key).getOrSet(key, value, expiryNano)
439439
}
440440

441441
func (s *shard[K, V]) getOrSet(key K, value V, expiryNano int64) (V, bool) {
@@ -512,7 +512,7 @@ func (s *shard[K, V]) getOrSet(key K, value V, expiryNano int64) (V, bool) {
512512
// set adds or updates a value in the cache.
513513
// expiryNano is Unix nanoseconds; 0 means no expiry.
514514
func (c *s3fifo[K, V]) set(key K, value V, expiryNano int64) {
515-
c.getShard(key).set(key, value, expiryNano)
515+
c.shard(key).set(key, value, expiryNano)
516516
}
517517

518518
func (s *shard[K, V]) set(key K, value V, expiryNano int64) {
@@ -563,7 +563,7 @@ func (s *shard[K, V]) set(key K, value V, expiryNano int64) {
563563

564564
// del removes a value from the cache.
565565
func (c *s3fifo[K, V]) del(key K) {
566-
c.getShard(key).delete(key)
566+
c.shard(key).delete(key)
567567
}
568568

569569
func (s *shard[K, V]) delete(key K) {

s3fifo_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ type plainKey struct {
484484
//nolint:gocognit // Test function intentionally exercises many code paths via subtests
485485
func TestS3FIFO_VariousKeyTypes(t *testing.T) {
486486
// Test that various key types work correctly with the sharding logic.
487-
// This exercises different code paths in getShard/shardIndexSlow.
487+
// This exercises different code paths in shard/shardIndexSlow.
488488

489489
t.Run("int", func(t *testing.T) {
490490
cache := newS3FIFO[int, string](&config{size: 100, smallRatio: 0.1, ghostRatio: 1.0})

0 commit comments

Comments
 (0)