diff options
| author | David Crawshaw <crawshaw@tailscale.com> | 2021-07-03 08:41:56 -0700 |
|---|---|---|
| committer | David Crawshaw <crawshaw@tailscale.com> | 2021-07-03 08:43:33 -0700 |
| commit | 9244c0447e44006a4325e42fbaace16309c612ef (patch) | |
| tree | 2a516670c8b96be14c9d1ff81a1d9ebd9768f12e /util/deephash/deephash.go | |
| parent | 700badd8f82bf12f098ced5f82d5a92ea46157e0 (diff) | |
| download | tailscale-crawshaw/deephash.tar.xz tailscale-crawshaw/deephash.zip | |
util/deephash: simplify hex encodecrawshaw/deephash
With https://go-review.googlesource.com/c/go/+/332689,
Before:
BenchmarkHash-24 62504 19250 ns/op 2297 B/op 58 allocs/op
BenchmarkHashMapAcyclic-24 39852 30119 ns/op 2532 B/op 202 allocs/op
After:
BenchmarkHash-24 62440 19271 ns/op 2298 B/op 58 allocs/op
BenchmarkHashMapAcyclic-24 39592 30307 ns/op 2532 B/op 202 allocs/op
Signed-off-by: David Crawshaw <crawshaw@tailscale.com>
Diffstat (limited to 'util/deephash/deephash.go')
| -rw-r--r-- | util/deephash/deephash.go | 8 |
1 files changed, 1 insertions, 7 deletions
diff --git a/util/deephash/deephash.go b/util/deephash/deephash.go index c116f0977..e047280c8 100644 --- a/util/deephash/deephash.go +++ b/util/deephash/deephash.go @@ -26,13 +26,7 @@ func calcHash(v interface{}) string { scratch := make([]byte, 0, 128) printTo(b, v, scratch) b.Flush() - scratch = h.Sum(scratch[:0]) - // The first sha256.Size bytes contain the hash. - // Hex-encode that into the next sha256.Size*2 bytes. - src := scratch[:sha256.Size] - dst := scratch[sha256.Size:cap(scratch)] - n := hex.Encode(dst, src) - return string(dst[:n]) + return hex.EncodeToString(h.Sum(scratch[:0])) } // UpdateHash sets last to the hash of v and reports whether its value changed. |
