-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
codec: streamline nil decoding: nil means zero value consistently
Previously, we had a TryDecodeAsNil that all formats implemented. However, the same formats did double duty by still checking if nil in stream when decoding a value. We introduce TryNil (replacing TryDecodeAsNil) which is used iff the type is a pointer and we need to set it to null if null was seen in the stream. Now, nil means zero value consistently, regardless of the context. In other words, a 'nil' in a stream means to reset the value to its zero state. A side effect of this is that the decode option 'DeleteOnNilMapValue` is a no-op. It is kept for compiling compatibility but has no effect during decoding. The main benefits are in the architecture - TryNil is only called if updating a pointer value - Nil is only handled at container boundaries: map, slice, null i.e. only when calling decDriver.ContainerType or decDriver.Read(Map|Array)Len ---- Also, reduce size of typeInfo by using a bitset flag instead of multiple bools. This gives us space (within 3*8 words) to store a reflect.Zero value in each typeInfo. This saves some allocation done when calling reflect.Zero(Type). ---- Add some code cleanup and re-organization.
- Loading branch information
Showing
26 changed files
with
6,159 additions
and
8,151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.