util/deephash: don't reflect.Copy if element type is a defined uint8

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick 2021-07-07 11:58:02 -07:00
parent df176c82f5
commit ddb8726c98
2 changed files with 8 additions and 1 deletions

View File

@ -125,6 +125,8 @@ func (h *hasher) int(i int) {
h.bw.Write(h.scratch[:8]) h.bw.Write(h.scratch[:8])
} }
var uint8Type = reflect.TypeOf(byte(0))
// print hashes v into w. // print hashes v into w.
// It reports whether it was able to do so without hitting a cycle. // It reports whether it was able to do so without hitting a cycle.
func (h *hasher) print(v reflect.Value) (acyclic bool) { 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 { if v.Kind() == reflect.Slice {
h.int(vLen) 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 vLen > 0 && vLen <= scratchSize {
// If it fits in scratch, avoid the Interface allocation. // If it fits in scratch, avoid the Interface allocation.
// It seems tempting to do this for all sizes, doing // It seems tempting to do this for all sizes, doing

View File

@ -15,8 +15,10 @@
"inet.af/netaddr" "inet.af/netaddr"
"tailscale.com/tailcfg" "tailscale.com/tailcfg"
"tailscale.com/types/ipproto"
"tailscale.com/util/dnsname" "tailscale.com/util/dnsname"
"tailscale.com/version" "tailscale.com/version"
"tailscale.com/wgengine/filter"
"tailscale.com/wgengine/router" "tailscale.com/wgengine/router"
"tailscale.com/wgengine/wgcfg" "tailscale.com/wgengine/wgcfg"
) )
@ -126,6 +128,9 @@ func getVal() []interface{} {
{ID: 2, LoginName: "bar@foo.com"}, {ID: 2, LoginName: "bar@foo.com"},
}, },
}, },
filter.Match{
IPProto: []ipproto.Proto{1, 2, 3},
},
} }
} }