1
0
mirror of https://github.com/json-iterator/go.git synced 2025-11-26 22:40:13 +02:00

#54 support sort map keys

This commit is contained in:
Tao Wen
2017-06-16 16:46:30 +08:00
parent e0e2423e9a
commit 69bc64b6d8
4 changed files with 110 additions and 10 deletions

View File

@@ -487,6 +487,9 @@ func encoderOfMap(cfg *frozenConfig, typ reflect.Type) (Encoder, error) {
return nil, err
}
mapInterface := reflect.New(typ).Elem().Interface()
encoderForMap := &mapEncoder{typ, elemType, encoder, *((*emptyInterface)(unsafe.Pointer(&mapInterface)))}
return encoderForMap, nil
if cfg.sortMapKeys {
return &sortKeysMapEncoder{typ, elemType, encoder, *((*emptyInterface)(unsafe.Pointer(&mapInterface)))}, nil
} else {
return &mapEncoder{typ, elemType, encoder, *((*emptyInterface)(unsafe.Pointer(&mapInterface)))}, nil
}
}