From ddb8726c98b797a096225554733c8609926b57c6 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 7 Jul 2021 11:58:02 -0700 Subject: [PATCH] util/deephash: don't reflect.Copy if element type is a defined uint8 Signed-off-by: Brad Fitzpatrick --- util/deephash/deephash.go | 4 +++- util/deephash/deephash_test.go | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/util/deephash/deephash.go b/util/deephash/deephash.go index 083020095..f688a26de 100644 --- a/util/deephash/deephash.go +++ b/util/deephash/deephash.go @@ -125,6 +125,8 @@ func (h *hasher) int(i int) { h.bw.Write(h.scratch[:8]) } +var uint8Type = reflect.TypeOf(byte(0)) + // print hashes v into w. // It reports whether it was able to do so without hitting a cycle. func (h *hasher) print(v reflect.Value) (acyclic bool) { @@ -172,7 +174,7 @@ func (h *hasher) print(v reflect.Value) (acyclic bool) { if v.Kind() == reflect.Slice { h.int(vLen) } - if v.Type().Elem().Kind() == reflect.Uint8 && v.CanInterface() { + if v.Type().Elem() == uint8Type && v.CanInterface() { if vLen > 0 && vLen <= scratchSize { // If it fits in scratch, avoid the Interface allocation. // It seems tempting to do this for all sizes, doing diff --git a/util/deephash/deephash_test.go b/util/deephash/deephash_test.go index 0bccf7802..b26414f7b 100644 --- a/util/deephash/deephash_test.go +++ b/util/deephash/deephash_test.go @@ -15,8 +15,10 @@ import ( "inet.af/netaddr" "tailscale.com/tailcfg" + "tailscale.com/types/ipproto" "tailscale.com/util/dnsname" "tailscale.com/version" + "tailscale.com/wgengine/filter" "tailscale.com/wgengine/router" "tailscale.com/wgengine/wgcfg" ) @@ -126,6 +128,9 @@ func getVal() []interface{} { {ID: 2, LoginName: "bar@foo.com"}, }, }, + filter.Match{ + IPProto: []ipproto.Proto{1, 2, 3}, + }, } }