Skip to content

Commit

Permalink
make map with size
Browse files Browse the repository at this point in the history
  • Loading branch information
petersunbag committed Feb 1, 2018
1 parent b8a91e7 commit bc55107
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions map.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ func newMapConverter(convertType *convertType) (m converter) {
func (m *mapConverter) convert(dPtr, sPtr unsafe.Pointer) {
sv := ptrToMapValue(m.sEmptyMapInterface, sPtr)
dv := ptrToMapValue(m.dEmptyMapInterface, dPtr)

keys := sv.MapKeys()
if dv.IsNil() {
dv.Set(reflect.MakeMap(m.dstTyp))
dv.Set(reflect.MakeMapWithSize(m.dstTyp, len(keys)))
}

for _, sKey := range sv.MapKeys() {
for _, sKey := range keys {
sValPtr := valuePtr(sv.MapIndex(sKey))
sKeyPtr := valuePtr(sKey)
dKey := reflect.New(m.dKeyTyp).Elem()
Expand Down

0 comments on commit bc55107

Please sign in to comment.