diff options
author | Keith Randall <khr@golang.org> | 2020-06-17 18:22:38 -0700 |
---|---|---|
committer | Keith Randall <khr@golang.org> | 2020-08-17 22:05:16 +0000 |
commit | 77a11c05d6a6f766c75f804ea9b8796f9a9f85a3 (patch) | |
tree | 473f3ba36178b531026cc25f006cdc41047e0178 /src/reflect | |
parent | ef9c8a38ad177fa7f48dfaad5d0e27f39a03529d (diff) | |
download | go-77a11c05d6a6f766c75f804ea9b8796f9a9f85a3.tar.gz go-77a11c05d6a6f766c75f804ea9b8796f9a9f85a3.zip |
reflect: remove depth from deepequal recursion
We aren't using it for anything. The visited map will terminate
any recursion for us.
Change-Id: I36e6bd8e34952123c2ed46323067e42928ec7168
Reviewed-on: https://go-review.googlesource.com/c/go/+/238759
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Diffstat (limited to 'src/reflect')
-rw-r--r-- | src/reflect/deepequal.go | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/reflect/deepequal.go b/src/reflect/deepequal.go index 8a2bf8b09e..be66464129 100644 --- a/src/reflect/deepequal.go +++ b/src/reflect/deepequal.go @@ -21,7 +21,7 @@ type visit struct { // Tests for deep equality using reflected types. The map argument tracks // comparisons that have already been seen, which allows short circuiting on // recursive types. -func deepValueEqual(v1, v2 Value, visited map[visit]bool, depth int) bool { +func deepValueEqual(v1, v2 Value, visited map[visit]bool) bool { if !v1.IsValid() || !v2.IsValid() { return v1.IsValid() == v2.IsValid() } @@ -29,8 +29,6 @@ func deepValueEqual(v1, v2 Value, visited map[visit]bool, depth int) bool { return false } - // 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(v1, v2) needs to return true for at least one of the types in the cycle, @@ -79,7 +77,7 @@ func deepValueEqual(v1, v2 Value, visited map[visit]bool, depth int) bool { switch v1.Kind() { case Array: for i := 0; i < v1.Len(); i++ { - if !deepValueEqual(v1.Index(i), v2.Index(i), visited, depth+1) { + if !deepValueEqual(v1.Index(i), v2.Index(i), visited) { return false } } @@ -95,7 +93,7 @@ func deepValueEqual(v1, v2 Value, visited map[visit]bool, depth int) bool { return true } for i := 0; i < v1.Len(); i++ { - if !deepValueEqual(v1.Index(i), v2.Index(i), visited, depth+1) { + if !deepValueEqual(v1.Index(i), v2.Index(i), visited) { return false } } @@ -104,15 +102,15 @@ func deepValueEqual(v1, v2 Value, visited map[visit]bool, depth int) bool { if v1.IsNil() || v2.IsNil() { return v1.IsNil() == v2.IsNil() } - return deepValueEqual(v1.Elem(), v2.Elem(), visited, depth+1) + return deepValueEqual(v1.Elem(), v2.Elem(), visited) case Ptr: if v1.Pointer() == v2.Pointer() { return true } - return deepValueEqual(v1.Elem(), v2.Elem(), visited, depth+1) + return deepValueEqual(v1.Elem(), v2.Elem(), visited) case Struct: for i, n := 0, v1.NumField(); i < n; i++ { - if !deepValueEqual(v1.Field(i), v2.Field(i), visited, depth+1) { + if !deepValueEqual(v1.Field(i), v2.Field(i), visited) { return false } } @@ -130,7 +128,7 @@ func deepValueEqual(v1, v2 Value, visited map[visit]bool, depth int) bool { for _, k := range v1.MapKeys() { val1 := v1.MapIndex(k) val2 := v2.MapIndex(k) - if !val1.IsValid() || !val2.IsValid() || !deepValueEqual(val1, val2, visited, depth+1) { + if !val1.IsValid() || !val2.IsValid() || !deepValueEqual(val1, val2, visited) { return false } } @@ -207,5 +205,5 @@ func DeepEqual(x, y interface{}) bool { if v1.Type() != v2.Type() { return false } - return deepValueEqual(v1, v2, make(map[visit]bool), 0) + return deepValueEqual(v1, v2, make(map[visit]bool)) } |