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

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
pull/2351/head
Brad Fitzpatrick 3 years ago
parent df176c82f5
commit ddb8726c98

@ -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

@ -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},
},
}
}

Loading…
Cancel
Save