Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
codec: Multiple fixes, enhancements and test expansion across the board.
Details below ... Expanded Tests across the board, including but not limited to: - non-string keys - chan - swallow (decode into equivalent of /dev/null) - zero - raw ext - map keys that are structs - canonical - decoding nil map value - ... Fixed issues: - expand set of options used in testing - use bitset(256|128) instead of a large array to test whether bits are set - allow decodeValue intelligently handle whether a function requires a pointer or not. This way, folks don't have to call Addr themselves. - use bounded arrays for the cache used during decodeNaked - decNaked: use an array of reflect.Value to pre-load all decNaked stuff - everyone calls into encodeValue or decodeValue (removing all cruft) - support recognizedRtid behind a flag - separate setting a value to its zero value, from decode. - remove many helpers (e.g. predecodevalue): now just a few methods do the right things - cleanup fast path: no tryNil argument needed, and the arg is either a pointer or a base value. - support arrays well in codecgen - full support for io.Reader passed to decode - msgpack: full support for strings read from a []byte codec: collection of correctness and simplification changes Move decNaked out of the Decoder struct. The Decoder struct was too big, and decNaked is only used if decoding into an empty interface{}. So make it an explicit request to grab a decNaked if doing DecodeNaked. Use a sync.Pool so that the decNaked's can be shared across multiple decodings. ---- Add SliceElementReset as a decode option, to align with MapValueReset and InterfaceReset. This eliminates the resetSliceElemToZeroValue constant. ---- Clean out comments and commented code blocks. ---- Move the code for getting a codec function into a single place. Previously, there was much duplication of the same logic in encode.go and decode.go. Now, we put a single type "codecFner" that is a member element of Decoder and Encoder. This means that getEncFn and getDecFn go away, and fast-path looks different, because the definition of encfn and decfn have changed. This will allow us move the code to be a member of the Handle later on, which should be where it belongs. ---- Use a single pool struct to consolidate how pools are used in the codebase, for decNaked, encStruct, etc. ---- Reduce bounds-checking in json.go, by looking up an index in the string just once, and setting into a char variable. Helped shave much time from json decoding. ---- codec: add error field to (De|En)coder to flag such as unusable until reset json: differentiate empty vs nil slice when encoding/decoding clean up encoding of chans codecgen: add support for NoExtensions Extensions support causes the receiver of CodecDecodeSelf to escape, which can have dramatic performance implications. Since extensions is a seldom used feature, it is not fair for everyone to pay the price. add String method to valueType, for debugging msgpack: support DecodeBytes where valueTypeBytes comes from a msgpack string container cbor: fix extension encoding - only encode the Value component of RawExt support new Decode Option: DeleteOnNilMapValue - DeleteOnNilMapValue controls how to decode a nil value in the stream. - add a test Ensure T or ... *****T are recognized as Selfer during encode or decode - to do this, always pass checkSelfer=true when getting the function for encode/decode separare values_test.go from values_flex_test.go Currently, we use the same file (values_test.go) for testing and benchmarks. However, our benchmarks compare codec against other (en|de)coders which are stricter and may support only maps with string keys. To support these 2 modes elegantly, we separate value_test.go, to be used by benchmarks, and values_flex_test.go to be used by codec tests. values_test.go will now be used for testing and benchmarks, but values_flex_test.go will only be used for testing. Fix: ensure we encode separator before encoding nil in struct2array mode of encode struct test: expand TestStruc to have fields of struct type with no omitempty. This makes the tests for omitempty more expansive, as the code takes 2 different paths if there are omitempty fields or not. optimize structFieldInfo, struct field lookup and (en|de)coding with no omitempty - Use a fixed array for the structFieldInfo instead of a slice. It uses same amount of memory (roughly) while reducing the array bounds checking. Due to this, we no longer support embedding over 16 levels deep. In practice, this is not a concern. - Also, introduct StructFieldNode which allows us use a cache when iterating a Struct during encoding and decoding, so we don't lookup Value.Field, Value.Elem and Value.IsNil repeatedly. - Determine whether a typeInfo has any omitEmpty fields early, so we can take a fast-path if we no omitEmpty is not a concern. add faster versions of readn3,4 and writen4,5 for use by json codec kInterface MUST take a settable interface value. ensure kMap honors that. decode: can decode into non-nil chan/slice/map/ptr or array, not just non-nil ptr
- Loading branch information