OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Deep equality test via reflection | 5 // Deep equality test via reflection |
6 | 6 |
7 package reflect | 7 package reflect |
8 | 8 |
9 // During deepValueEqual, must keep track of checks that are | 9 // During deepValueEqual, must keep track of checks that are |
10 // in progress. The comparison algorithm assumes that all | 10 // in progress. The comparison algorithm assumes that all |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 panic("Not reached") | 110 panic("Not reached") |
111 } | 111 } |
112 | 112 |
113 // DeepEqual tests for deep equality. It uses normal == equality where possible | 113 // DeepEqual tests for deep equality. It uses normal == equality where possible |
114 // but will scan members of arrays, slices, and fields of structs. It correctly | 114 // but will scan members of arrays, slices, and fields of structs. It correctly |
115 // handles recursive types. | 115 // handles recursive types. |
116 func DeepEqual(a1, a2 interface{}) bool { | 116 func DeepEqual(a1, a2 interface{}) bool { |
117 if a1 == nil || a2 == nil { | 117 if a1 == nil || a2 == nil { |
118 return a1 == a2 | 118 return a1 == a2 |
119 } | 119 } |
120 » v1 := NewValue(a1) | 120 » v1 := ValueOf(a1) |
121 » v2 := NewValue(a2) | 121 » v2 := ValueOf(a2) |
122 if v1.Type() != v2.Type() { | 122 if v1.Type() != v2.Type() { |
123 return false | 123 return false |
124 } | 124 } |
125 return deepValueEqual(v1, v2, make(map[uintptr]*visit), 0) | 125 return deepValueEqual(v1, v2, make(map[uintptr]*visit), 0) |
126 } | 126 } |
OLD | NEW |