aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2017-08-02 17:52:06 -0700
committerIan Lance Taylor <iant@golang.org>2017-08-04 22:22:03 +0000
commita279b53a18dbe317180e9e411ca7892294a62901 (patch)
tree321bb9d81b36ccabe928fbba08a92c9dc8919db2
parent909f409a8d21c69198fc4d3f9bc08b6774650980 (diff)
downloadgo-a279b53a18dbe317180e9e411ca7892294a62901.tar.gz
go-a279b53a18dbe317180e9e411ca7892294a62901.zip
reflect: document how DeepEqual handles cycles
Fixes #20428 Change-Id: Ia450e615728efd4ccb6e42117b547cac162f13a3 Reviewed-on: https://go-review.googlesource.com/52931 Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
-rw-r--r--src/reflect/deepequal.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/reflect/deepequal.go b/src/reflect/deepequal.go
index f3fd7043e5..2fdd6a3d82 100644
--- a/src/reflect/deepequal.go
+++ b/src/reflect/deepequal.go
@@ -178,6 +178,12 @@ func deepValueEqual(v1, v2 Value, visited map[visit]bool, depth int) bool {
// DeepEqual has been defined so that the same short-cut applies
// to slices and maps: if x and y are the same slice or the same map,
// they are deeply equal regardless of content.
+//
+// As DeepEqual traverses the data values it may find a cycle. The
+// second and subsequent times that DeepEqual compares two pointer
+// values that have been compared before, it treats the values as
+// equal rather than examining the values to which they point.
+// This ensures that DeepEqual terminates.
func DeepEqual(x, y interface{}) bool {
if x == nil || y == nil {
return x == y