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])
}
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