Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
33be0c64
Commit
33be0c64
authored
Sep 03, 2009
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nil in DeepEqual
R=r DELTA=13 (5 added, 6 deleted, 2 changed) OCL=34337 CL=34343
parent
107d4043
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
8 deletions
+7
-8
all_test.go
src/pkg/reflect/all_test.go
+2
-0
deepequal.go
src/pkg/reflect/deepequal.go
+5
-8
No files found.
src/pkg/reflect/all_test.go
View file @
33be0c64
...
...
@@ -378,6 +378,8 @@ var deepEqualTests = []DeepEqualTest {
DeepEqualTest
{
map
[
int
]
string
{
1
:
"one"
,
2
:
"txo"
},
map
[
int
]
string
{
2
:
"two"
,
1
:
"one"
},
false
},
DeepEqualTest
{
map
[
int
]
string
{
1
:
"one"
,
},
map
[
int
]
string
{
2
:
"two"
,
1
:
"one"
},
false
},
DeepEqualTest
{
map
[
int
]
string
{
2
:
"two"
,
1
:
"one"
},
map
[
int
]
string
{
1
:
"one"
,
},
false
},
DeepEqualTest
{
nil
,
1
,
false
},
DeepEqualTest
{
1
,
nil
,
false
},
// Mismatched types
DeepEqualTest
{
1
,
1.0
,
false
},
...
...
src/pkg/reflect/deepequal.go
View file @
33be0c64
...
...
@@ -22,11 +22,8 @@ type visit struct {
// comparisons that have already been seen, which allows short circuiting on
// recursive types.
func
deepValueEqual
(
v1
,
v2
Value
,
visited
map
[
uintptr
]
*
visit
,
depth
int
)
bool
{
if
v1
==
nil
{
return
v2
==
nil
}
if
v2
==
nil
{
return
false
if
v1
==
nil
||
v2
==
nil
{
return
v1
==
v2
}
if
v1
.
Type
()
!=
v2
.
Type
()
{
return
false
;
...
...
@@ -126,11 +123,11 @@ func deepValueEqual(v1, v2 Value, visited map[uintptr]*visit, depth int) bool {
// but will scan members of arrays, slices, and fields of structs. It correctly
// handles recursive types.
func
DeepEqual
(
a1
,
a2
interface
{})
bool
{
if
a1
==
nil
||
a2
==
nil
{
return
a1
==
a2
;
}
v1
:=
NewValue
(
a1
);
v2
:=
NewValue
(
a2
);
if
v1
==
nil
{
return
v1
==
v2
;
}
if
v1
.
Type
()
!=
v2
.
Type
()
{
return
false
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment