Skip to content

Commit

Permalink
Merge pull request #93 from juju812/master
Browse files Browse the repository at this point in the history
append destslice size only if dest size smaller than src
  • Loading branch information
jinzhu authored Mar 17, 2021
2 parents d711dc7 + 1d40514 commit fc3adf5
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions copier.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,17 @@ func copier(toValue interface{}, fromValue interface{}, opt Option) (err error)

if isSlice {
if dest.Addr().Type().AssignableTo(to.Type().Elem()) {
to.Set(reflect.Append(to, dest.Addr()))
if to.Len() < i+1 {
to.Set(reflect.Append(to, dest.Addr()))
} else {
set(to.Index(i), dest.Addr(), opt.DeepCopy)
}
} else if dest.Type().AssignableTo(to.Type().Elem()) {
to.Set(reflect.Append(to, dest))
if to.Len() < i+1 {
to.Set(reflect.Append(to, dest))
} else {
set(to.Index(i), dest, opt.DeepCopy)
}
}
} else if initDest {
to.Set(dest)
Expand Down

0 comments on commit fc3adf5

Please sign in to comment.