From cee09816e39660ec208e3de36862a33b6d4ba755 Mon Sep 17 00:00:00 2001 From: Fei Ni Date: Sun, 11 Jun 2017 16:28:31 +0800 Subject: [PATCH] decoder/encoder;float precision doc --- feature_adapter.go | 4 ++-- feature_reflect.go | 25 ++++++++++++++----------- feature_stream_float.go | 2 ++ 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/feature_adapter.go b/feature_adapter.go index e98a913..09cf449 100644 --- a/feature_adapter.go +++ b/feature_adapter.go @@ -6,9 +6,9 @@ // // "JSON and Go" // (https://golang.org/doc/articles/json_and_go.html) -// gives a description of how Marshall/Unmarshall operate +// gives a description of how Marshal/Unmarshal operate // between arbitrary or predefined json objects and bytes, -// and it applies to jsoniter.Marshall/Unmarshall. +// and it applies to jsoniter.Marshal/Unmarshal as well. package jsoniter import ( diff --git a/feature_reflect.go b/feature_reflect.go index 9449a0d..7090535 100644 --- a/feature_reflect.go +++ b/feature_reflect.go @@ -9,19 +9,22 @@ import ( "unsafe" ) -/* -Reflection on type to create decoders, which is then cached -Reflection on value is avoided as we can, as the reflect.Value itself will allocate, with following exceptions -1. create instance of new value, for example *int will need a int to be allocated -2. append to slice, if the existing cap is not enough, allocate will be done using Reflect.New -3. assignment to map, both key and value will be reflect.Value -For a simple struct binding, it will be reflect.Value free and allocation free -*/ - +// Don't confuse jsoniter.Decoder with json.Decoder. +// jsoniter.Decoder/Encoder are an internal types registered to cache as needed. +// For json.Decoder's adapter, refer to jsoniter.AdapterDecoder(todo link). +// +// Reflection on type to create decoders, which is then cached +// Reflection on value is avoided as we can, as the reflect.Value itself will allocate, with following exceptions +// 1. create instance of new value, for example *int will need a int to be allocated +// 2. append to slice, if the existing cap is not enough, allocate will be done using Reflect.New +// 3. assignment to map, both key and value will be reflect.Value +// For a simple struct binding, it will be reflect.Value free and allocation free type Decoder interface { decode(ptr unsafe.Pointer, iter *Iterator) } - +// Don't confuse jsoniter.Encoder with json.Encoder. +// jsoniter.Decoder/Encoder are an internal types registered to cache as needed. +// For json.Encoder's adapter, refer to jsoniter.AdapterEncoder(todo godoc link). type Encoder interface { isEmpty(ptr unsafe.Pointer) bool encode(ptr unsafe.Pointer, stream *Stream) @@ -166,7 +169,7 @@ func CleanDecoders() { atomic.StorePointer(&DECODERS, unsafe.Pointer(&map[string]Decoder{})) } -// CleanEncoders cleans decoders registered or cached +// CleanEncoders cleans encoders registered or cached func CleanEncoders() { typeEncoders = map[string]Encoder{} fieldEncoders = map[string]Encoder{} diff --git a/feature_stream_float.go b/feature_stream_float.go index a2538f4..65cf572 100644 --- a/feature_stream_float.go +++ b/feature_stream_float.go @@ -75,6 +75,8 @@ func (stream *Stream) WriteFloat64Lossy(val float64) { } } +// EnableLossyFloatMarshalling keeps 10**(-6) precision +// for float variables for better performance. func EnableLossyFloatMarshalling() { // for better performance RegisterTypeEncoder("float32", func(ptr unsafe.Pointer, stream *Stream) {