Avoid generating empty closures for fieldless enums
For many enums, this avoids generating lots of tiny stubs that need to be codegen'd and then inlined and removed by LLVM.
This commit is contained in:
parent
65f3f8b220
commit
3228603cce
3 changed files with 46 additions and 7 deletions
|
@ -247,13 +247,24 @@ fn encodable_body(
|
|||
})
|
||||
.collect();
|
||||
|
||||
let result = quote! { ::rustc_serialize::Encoder::emit_enum_variant(
|
||||
__encoder,
|
||||
#variant_name,
|
||||
#variant_idx,
|
||||
#field_idx,
|
||||
|__encoder| { ::std::result::Result::Ok({ #encode_fields }) }
|
||||
) };
|
||||
let result = if field_idx != 0 {
|
||||
quote! {
|
||||
::rustc_serialize::Encoder::emit_enum_variant(
|
||||
__encoder,
|
||||
#variant_name,
|
||||
#variant_idx,
|
||||
#field_idx,
|
||||
|__encoder| { ::std::result::Result::Ok({ #encode_fields }) }
|
||||
)
|
||||
}
|
||||
} else {
|
||||
quote! {
|
||||
::rustc_serialize::Encoder::emit_fieldless_enum_variant::<#variant_idx>(
|
||||
__encoder,
|
||||
#variant_name,
|
||||
)
|
||||
}
|
||||
};
|
||||
variant_idx += 1;
|
||||
result
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue