@@ -119,53 +119,58 @@ func newMyersSlice(c config, lhs, rhs interface{}, visited *visited) (Differ, er
119
119
}
120
120
121
121
func newSlice (c config , lhs , rhs interface {}, visited * visited ) (Differ , error ) {
122
- var diffs []Differ
123
- var indices []int
122
+ var (
123
+ diffs []Differ
124
+ indices []int
125
+ err error
126
+ typesDiffer bool
127
+ )
124
128
125
129
lhsVal := reflect .ValueOf (lhs )
126
130
rhsVal := reflect .ValueOf (rhs )
127
131
128
- if typesDiffer , err : = sliceTypesDiffer (lhs , rhs ); err != nil {
132
+ if typesDiffer , err = sliceTypesDiffer (lhs , rhs ); err != nil {
129
133
return slice {
130
134
lhs : lhs ,
131
135
rhs : rhs ,
132
136
}, err
133
137
} else if ! typesDiffer {
134
- nElems := lhsVal .Len ()
135
- if rhsVal .Len () > nElems {
136
- nElems = rhsVal .Len ()
137
- }
138
-
139
- for i := 0 ; i < nElems ; i ++ {
140
- indices = append (indices , i )
141
- if i < lhsVal .Len () && i < rhsVal .Len () {
142
- diff , err := diff (c , lhsVal .Index (i ).Interface (), rhsVal .Index (i ).Interface (), visited )
143
- diffs = append (diffs , diff )
144
-
145
- if err != nil {
146
- return slice {
147
- lhs : lhs ,
148
- rhs : rhs ,
149
- diffs : diffs ,
150
- indices : indices ,
151
- }, err
152
- }
153
- continue
154
- }
155
- if i >= rhsVal .Len () {
156
- diffs = append (diffs , sliceMissing {lhsVal .Index (i ).Interface ()})
157
- continue
158
- }
159
- diffs = append (diffs , sliceExcess {rhsVal .Index (i ).Interface ()})
160
- }
138
+ indices , diffs , err = sliceNewSameTypes (c , lhsVal , rhsVal , visited )
161
139
}
162
140
163
141
return slice {
164
142
lhs : lhs ,
165
143
rhs : rhs ,
166
144
diffs : diffs ,
167
145
indices : indices ,
168
- }, nil
146
+ }, err
147
+ }
148
+
149
+ func sliceNewSameTypes (c config , lhsVal , rhsVal reflect.Value , visited * visited ) (indices []int , diffs []Differ , err error ) {
150
+ nElems := lhsVal .Len ()
151
+ if rhsVal .Len () > nElems {
152
+ nElems = rhsVal .Len ()
153
+ }
154
+
155
+ for i := 0 ; i < nElems ; i ++ {
156
+ indices = append (indices , i )
157
+ if i < lhsVal .Len () && i < rhsVal .Len () {
158
+ diff , err := diff (c , lhsVal .Index (i ).Interface (), rhsVal .Index (i ).Interface (), visited )
159
+ diffs = append (diffs , diff )
160
+
161
+ if err != nil {
162
+ return indices , diffs , err
163
+ }
164
+ continue
165
+ }
166
+ if i >= rhsVal .Len () {
167
+ diffs = append (diffs , sliceMissing {lhsVal .Index (i ).Interface ()})
168
+ continue
169
+ }
170
+ diffs = append (diffs , sliceExcess {rhsVal .Index (i ).Interface ()})
171
+ }
172
+
173
+ return indices , diffs , nil
169
174
}
170
175
171
176
func sliceTypesDiffer (lhs , rhs interface {}) (bool , error ) {
0 commit comments