Skip to content

Commit fb4b8a6

Browse files
committed
Update Cache.Add to use helper.HashString
* removes direct import of xxhash/v2 * replaces calls to `xxhash.Sum64` with `helper.HashString` * fixes typo in `cache_test.go` benchmark * updates go.mod to match removal of direct import
1 parent be9addf commit fb4b8a6

File tree

3 files changed

+4
-6
lines changed

3 files changed

+4
-6
lines changed

cache/cache.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111
"sync/atomic"
1212
"time"
1313

14-
"github.com/cespare/xxhash/v2"
15-
1614
"github.com/go-graphite/go-carbon/helper"
1715
"github.com/go-graphite/go-carbon/points"
1816
"github.com/go-graphite/go-carbon/tags"
@@ -334,9 +332,9 @@ func (c *Cache) Add(p *points.Points) {
334332
if c.newMetricsChan != nil && c.newMetricCf != nil {
335333
// add metric to new metric channel if missed in bloom
336334
// despite what we have it in cache (new behaviour)
337-
if !c.newMetricCf.Has(xxhash.Sum64([]byte(p.Metric))) {
335+
if !c.newMetricCf.Has(helper.HashString(p.Metric)) {
338336
sendMetricToNewMetricChan(c, p.Metric)
339-
c.newMetricCf.Add(xxhash.Sum64([]byte(p.Metric)))
337+
c.newMetricCf.Add(helper.HashString(p.Metric))
340338
}
341339

342340
}

cache/cache_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,5 @@ func benchmarkStrategy(b *testing.B, strategy string) {
9696
}
9797

9898
func BenchmarkUpdateQueueMax(b *testing.B) { benchmarkStrategy(b, "max") }
99-
func BenchmarkUpdateQueueSort(b *testing.B) { benchmarkStrategy(b, "sort") }
99+
func BenchmarkUpdateQueueSort(b *testing.B) { benchmarkStrategy(b, "sorted") }
100100
func BenchmarkUpdateQueueNoop(b *testing.B) { benchmarkStrategy(b, "noop") }

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ require (
3636
)
3737

3838
require (
39-
github.com/cespare/xxhash/v2 v2.3.0
4039
github.com/greatroar/blobloom v0.8.1
4140
github.com/zeebo/xxh3 v1.0.2
4241
golang.org/x/net v0.43.0
@@ -51,6 +50,7 @@ require (
5150
cloud.google.com/go/iam v1.5.2 // indirect
5251
cloud.google.com/go/pubsub/v2 v2.0.0 // indirect
5352
github.com/beorn7/perks v1.0.1 // indirect
53+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
5454
github.com/davecgh/go-spew v1.1.1 // indirect
5555
github.com/eapache/go-resiliency v1.7.0 // indirect
5656
github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 // indirect

0 commit comments

Comments
 (0)