-
Notifications
You must be signed in to change notification settings - Fork 234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
inception: Reset undefined fields when reusing objects. #195
Conversation
{{with $fieldName := $field.Name | printf "uj.%s"}} | ||
{{if eq $field.Pointer true}} | ||
{{$fieldName}} = nil | ||
{{else if eq $field.Typ.Kind ` + strconv.FormatUint(uint64(reflect.Interface), 10) + `}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of this should be properly indented with tabs so the resulting code doesn't change with gofmt (like the other templates here).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While nice, it doesn't matter too much, the generated code is all ran through fmt at the end, so the templates don't need to be whitespace perfect
Looks very useful and would surely prevent bugs. I think it should get some test cases? |
@pquerna did you have a look at this? |
75a7db5
to
65f05c1
Compare
@pquerna I just updated the pull request with code that hides this feature behind a command line flag. This is needed for ffjson to continue being a drop in replacement for the normal json. I also improved the test case and squashed all commits into one. I also did some benchmarking and it doesn't affect the performance at all, which is expected as it's only a couple of if statements. I think you can really merge this now so other people can also use it. |
Oh and I also fixed |
@pquerna is this project dead? |
Thank you. |
When reusing objects with sync.Pool, for example, and unmarshaling
objects, this resets the old fields, which are not defined in the
current JSON to their Zero values.
For example:
after marshalling all JSON objects.