util/deephash: simplify canMemHash (#5384)

Put the t.Size() == 0 check first since this is applicable in all cases.
Drop the last struct field conditional since this is covered by the
sumFieldSize check at the end.

Signed-off-by: Joe Tsai <joetsai@digital-static.net>
This commit is contained in:
Joe Tsai
2022-08-15 22:22:18 -07:00
committed by GitHub
parent 766ea96adf
commit c200229f9e
2 changed files with 21 additions and 22 deletions

View File

@@ -379,20 +379,18 @@ func TestCanMemHash(t *testing.T) {
_ uint8
_ int
}{}, false}, // gap
{
struct {
_ structs.Incomparable // if not last, zero-width
x int
}{},
true,
},
{
struct {
x int
_ structs.Incomparable // zero-width last: has space, can't memhash
}{},
false,
}}
{struct {
_ structs.Incomparable // if not last, zero-width
x int
}{}, true},
{struct {
x int
_ structs.Incomparable // zero-width last: has space, can't memhash
}{},
false},
{[0]chan bool{}, true},
{struct{ f [0]func() }{}, true},
}
for _, tt := range tests {
got := canMemHash(reflect.TypeOf(tt.val))
if got != tt.want {