Skip to content
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

Skip_serializing_if function is invoked too many times #1050

Open
dtolnay opened this issue Sep 9, 2017 · 0 comments
Open

Skip_serializing_if function is invoked too many times #1050

dtolnay opened this issue Sep 9, 2017 · 0 comments
Labels

Comments

@dtolnay
Copy link
Member

dtolnay commented Sep 9, 2017

#[derive(Serialize)]
struct S {
    #[serde(skip_serializing_if = "skip")]
    a: usize,
}

This turns into (effectively):

let len = if skip(&self.a) { 0 } else { 1 };
let mut state = serializer.serialize_struct("S", len)?;
if !skip(&self.a) {
    state.serialize_field("a", &self.a)?;
}
state.end()

It would be more reasonable like this:

let skip_a = skip(&self.a);
let len = if skip_a { 0 } else { 1 };
let mut state = serializer.serialize_struct("S", len)?;
if !skip_a {
    state.serialize_field("a", &self.a)?;
}
state.end()
@dtolnay dtolnay added the derive label Sep 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

1 participant