all: use any instead of interface{}

My favorite part of generics.

Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
This commit is contained in:
Josh Bleecher Snyder
2022-03-16 16:27:57 -07:00
committed by Josh Bleecher Snyder
parent 5f176f24db
commit 0868329936
88 changed files with 204 additions and 204 deletions
+4 -4
View File
@@ -113,11 +113,11 @@ func (h *hasher) sum() (s Sum) {
}
var hasherPool = &sync.Pool{
New: func() interface{} { return new(hasher) },
New: func() any { return new(hasher) },
}
// Hash returns the hash of v.
func Hash(v interface{}) (s Sum) {
func Hash(v any) (s Sum) {
h := hasherPool.Get().(*hasher)
defer hasherPool.Put(h)
h.reset()
@@ -130,7 +130,7 @@ func Hash(v interface{}) (s Sum) {
}
// Update sets last to the hash of v and reports whether its value changed.
func Update(last *Sum, v ...interface{}) (changed bool) {
func Update(last *Sum, v ...any) (changed bool) {
sum := Hash(v)
if sum == *last {
// unchanged.
@@ -304,7 +304,7 @@ type mapHasher struct {
}
var mapHasherPool = &sync.Pool{
New: func() interface{} { return new(mapHasher) },
New: func() any { return new(mapHasher) },
}
type valueCache map[reflect.Type]reflect.Value
+6 -6
View File
@@ -35,8 +35,8 @@ func (p appendBytes) AppendTo(b []byte) []byte {
}
func TestHash(t *testing.T) {
type tuple [2]interface{}
type iface struct{ X interface{} }
type tuple [2]any
type iface struct{ X any }
type scalars struct {
I8 int8
I16 int16
@@ -132,8 +132,8 @@ func TestDeepHash(t *testing.T) {
}
}
func getVal() []interface{} {
return []interface{}{
func getVal() []any {
return []any{
&wgcfg.Config{
Name: "foo",
Addresses: []netaddr.IPPrefix{netaddr.IPPrefixFrom(netaddr.IPFrom16([16]byte{3: 3}), 5)},
@@ -321,10 +321,10 @@ func TestExhaustive(t *testing.T) {
// verify this doesn't loop forever, as it used to (Issue 2340)
func TestMapCyclicFallback(t *testing.T) {
type T struct {
M map[string]interface{}
M map[string]any
}
v := &T{
M: map[string]interface{}{},
M: map[string]any{},
}
v.M["m"] = v.M
Hash(v)