Skip to content

Commit c4e66f3

Browse files
committed
[chore] small nits in converter HashResource, no performance impact
Signed-off-by: Bogdan Drutu <[email protected]>
1 parent 3e50dcd commit c4e66f3

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

Diff for: pkg/stanza/adapter/converter.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -258,22 +258,22 @@ func HashResource(resource map[string]any) uint64 {
258258
}
259259

260260
for _, k := range hw.keySlice {
261-
hw.h.Write([]byte(k)) //nolint:errcheck
262-
hw.h.Write(pairSep) //nolint:errcheck
261+
_, _ = hw.h.WriteString(k)
262+
_, _ = hw.h.Write(pairSep)
263263

264264
switch t := resource[k].(type) {
265265
case string:
266-
hw.h.Write([]byte(t)) //nolint:errcheck
266+
_, _ = hw.h.WriteString(t)
267267
case []byte:
268-
hw.h.Write(t) //nolint:errcheck
268+
_, _ = hw.h.Write(t)
269269
case bool, int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64:
270270
binary.Write(hw.h, binary.BigEndian, t) //nolint:errcheck // nothing to do about it
271271
default:
272272
b, _ := json.Marshal(t)
273-
hw.h.Write(b) //nolint:errcheck
273+
_, _ = hw.h.Write(b)
274274
}
275275

276-
hw.h.Write(pairSep) //nolint:errcheck
276+
_, _ = hw.h.Write(pairSep)
277277
}
278278

279279
return hw.h.Sum64()

Diff for: pkg/stanza/adapter/converter_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
func BenchmarkConvertSimple(b *testing.B) {
2121
b.StopTimer()
2222
ent := entry.New()
23+
b.ReportAllocs()
2324
b.StartTimer()
2425

2526
for i := 0; i < b.N; i++ {
@@ -30,6 +31,7 @@ func BenchmarkConvertSimple(b *testing.B) {
3031
func BenchmarkConvertComplex(b *testing.B) {
3132
b.StopTimer()
3233
ent := complexEntry()
34+
b.ReportAllocs()
3335
b.StartTimer()
3436

3537
for i := 0; i < b.N; i++ {
@@ -860,6 +862,10 @@ func BenchmarkGetResourceIDComplexResource(b *testing.B) {
860862

861863
func getResource() map[string]any {
862864
return map[string]any{
865+
"bool": true,
866+
"int": 123,
867+
"double": 12.34,
868+
"string": "hello",
863869
"file.name": "filename.log",
864870
"file.directory": "/some_directory",
865871
"host.name": "localhost",

0 commit comments

Comments
 (0)