diff --git a/internal/deephash/deephash.go b/internal/deephash/deephash.go index 8706c199f..16b89ac4e 100644 --- a/internal/deephash/deephash.go +++ b/internal/deephash/deephash.go @@ -240,12 +240,16 @@ func hashMapAcyclic(w *bufio.Writer, v reflect.Value, visited map[uintptr]bool) defer mapHasherPool.Put(mh) mh.Reset() iter := v.MapRange() + k := reflect.New(v.Type().Key()).Elem() + e := reflect.New(v.Type().Elem()).Elem() for iter.Next() { + key := iterKey(iter, k) + val := iterVal(iter, e) mh.startEntry() - if !print(mh.bw, iter.Key(), visited) { + if !print(mh.bw, key, visited) { return false } - if !print(mh.bw, iter.Value(), visited) { + if !print(mh.bw, val, visited) { return false } mh.endEntry() diff --git a/internal/deephash/mapiter.go b/internal/deephash/mapiter.go new file mode 100644 index 000000000..a45275dc0 --- /dev/null +++ b/internal/deephash/mapiter.go @@ -0,0 +1,17 @@ +// Copyright (c) 2021 Tailscale Inc & AUTHORS All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build !tailscale_go + +package deephash + +import "reflect" + +func iterKey(iter *reflect.MapIter, scratch reflect.Value) reflect.Value { + return iter.Key() +} + +func iterVal(iter *reflect.MapIter, scratch reflect.Value) reflect.Value { + return iter.Value() +} diff --git a/internal/deephash/mapiter_future.go b/internal/deephash/mapiter_future.go new file mode 100644 index 000000000..6e18dbd6a --- /dev/null +++ b/internal/deephash/mapiter_future.go @@ -0,0 +1,19 @@ +// Copyright (c) 2021 Tailscale Inc & AUTHORS All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build tailscale_go + +package deephash + +import "reflect" + +func iterKey(iter *reflect.MapIter, scratch reflect.Value) reflect.Value { + iter.SetKey(scratch) + return scratch +} + +func iterVal(iter *reflect.MapIter, scratch reflect.Value) reflect.Value { + iter.SetValue(scratch) + return scratch +}