diff options
Diffstat (limited to 'libgo/go/reflect/deepequal.go')
-rw-r--r-- | libgo/go/reflect/deepequal.go | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/libgo/go/reflect/deepequal.go b/libgo/go/reflect/deepequal.go index 3743e8042d..f3fd7043e5 100644 --- a/libgo/go/reflect/deepequal.go +++ b/libgo/go/reflect/deepequal.go @@ -9,7 +9,7 @@ package reflect import "unsafe" // During deepValueEqual, must keep track of checks that are -// in progress. The comparison algorithm assumes that all +// in progress. The comparison algorithm assumes that all // checks in progress are true when it reencounters them. // Visited comparisons are stored in a map indexed by visit. type visit struct { @@ -30,9 +30,13 @@ func deepValueEqual(v1, v2 Value, visited map[visit]bool, depth int) bool { } // if depth > 10 { panic("deepValueEqual") } // for debugging + + // We want to avoid putting more in the visited map than we need to. + // For any possible reference cycle that might be encountered, + // hard(t) needs to return true for at least one of the types in the cycle. hard := func(k Kind) bool { switch k { - case Array, Map, Slice, Struct: + case Map, Slice, Ptr, Interface: return true } return false @@ -142,8 +146,9 @@ func deepValueEqual(v1, v2 Value, visited map[visit]bool, depth int) bool { // // Interface values are deeply equal if they hold deeply equal concrete values. // -// Map values are deeply equal if they are the same map object -// or if they have the same length and their corresponding keys +// Map values are deeply equal when all of the following are true: +// they are both nil or both non-nil, they have the same length, +// and either they are the same map object or their corresponding keys // (matched using Go equality) map to deeply equal values. // // Pointer values are deeply equal if they are equal using Go's == operator |