mirror of
https://github.com/tailscale/tailscale.git
synced 2025-12-05 04:11:59 +00:00
util/deephash: add AppendSum method (#5768)
This method can be used to obtain the hex-formatted deephash.Sum instance without allocations. Signed-off-by: Andrew Dunham <andrew@du.nham.ca>
This commit is contained in:
@@ -1050,3 +1050,25 @@ func FuzzAddr(f *testing.F) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestAppendTo(t *testing.T) {
|
||||
v := getVal()
|
||||
h := Hash(v)
|
||||
sum := h.AppendTo(nil)
|
||||
|
||||
if s := h.String(); s != string(sum) {
|
||||
t.Errorf("hash sum mismatch; h.String()=%q h.AppendTo()=%q", s, string(sum))
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkAppendTo(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
v := getVal()
|
||||
h := Hash(v)
|
||||
|
||||
hashBuf := make([]byte, 0, 100)
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
hashBuf = h.AppendTo(hashBuf[:0])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user