-
-
Notifications
You must be signed in to change notification settings - Fork 195
feat: Dont make copies of structs for validation #737
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #737 +/- ##
=======================================
Coverage 77.94% 77.94%
=======================================
Files 22 22
Lines 7998 7998
=======================================
Hits 6234 6234
Misses 1349 1349
Partials 415 415 🚀 New features to boost your workflow:
|
b6dea53
to
69ce48c
Compare
@@ -1442,7 +1442,7 @@ func (d *Decoder) decodeStruct(ctx context.Context, dst reflect.Value, src ast.N | |||
} | |||
|
|||
if d.validator != nil { | |||
if err := d.validator.Struct(dst.Interface()); err != nil { | |||
if err := d.validator.Struct(dst.Addr().Interface()); err != nil { |
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.
dst
is guaranteed to be addressable. See this line.
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.
Pull Request Overview
This PR modifies the struct validation process by passing a pointer to the validator instead of a value, preventing unnecessary copying of structs.
- Changed the validator call from using dst.Interface() to dst.Addr().Interface()
- Improves efficiency by avoiding struct copies in validation
Comments suppressed due to low confidence (1)
decode.go:1445
- Consider verifying that 'dst' is addressable before calling .Addr(), to ensure that this change does not lead to runtime panics when 'dst' is not addressable.
if err := d.validator.Struct(dst.Addr().Interface()); err != nil {
Thanks! You can close my original PR #665 |
LGTM 👍 |
This reverts commit 04f9bb5.
Following this comment, I took over the original PR and updated it.
Before submitting your PR, please confirm the following.