Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(634)

Side by Side Diff: src/pkg/reflect/deepequal.go

Issue 5297042: code review 5297042: [release-branch.r58] reflect: disallow Interface method... (Closed)
Patch Set: diff -r d292bc788668 https://go.googlecode.com/hg/ Created 12 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pkg/reflect/all_test.go ('k') | src/pkg/reflect/value.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 return false 97 return false
98 } 98 }
99 for _, k := range v1.MapKeys() { 99 for _, k := range v1.MapKeys() {
100 if !deepValueEqual(v1.MapIndex(k), v2.MapIndex(k), visit ed, depth+1) { 100 if !deepValueEqual(v1.MapIndex(k), v2.MapIndex(k), visit ed, depth+1) {
101 return false 101 return false
102 } 102 }
103 } 103 }
104 return true 104 return true
105 default: 105 default:
106 // Normal equality suffices 106 // Normal equality suffices
107 » » return v1.Interface() == v2.Interface() 107 » » return valueInterface(v1, false) == valueInterface(v2, false)
108 } 108 }
109 109
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 := ValueOf(a1) 120 v1 := ValueOf(a1)
121 v2 := ValueOf(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 }
OLDNEW
« no previous file with comments | « src/pkg/reflect/all_test.go ('k') | src/pkg/reflect/value.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b