u8 tags for smaller enums
100% of the serialized enums during libcore compilation fit into the smaller tag, and this eliminates hitting the leb128 code for coding/decoding when we can statically guarantee that's not required. 30% of all leb128 integers serialized in libcore (12981183 total) come from the usize's removed here.
This commit is contained in:
parent
190f4c9611
commit
5e8f67bbc9
@ -76,8 +76,17 @@ fn decodable_body(
|
|||||||
ty_name,
|
ty_name,
|
||||||
variants.len()
|
variants.len()
|
||||||
);
|
);
|
||||||
|
let tag = if variants.len() < u8::MAX as usize {
|
||||||
quote! {
|
quote! {
|
||||||
match ::rustc_serialize::Decoder::read_usize(__decoder) {
|
::rustc_serialize::Decoder::read_u8(__decoder) as usize
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
quote! {
|
||||||
|
::rustc_serialize::Decoder::read_usize(__decoder)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
quote! {
|
||||||
|
match #tag {
|
||||||
#match_inner
|
#match_inner
|
||||||
n => panic!(#message, n),
|
n => panic!(#message, n),
|
||||||
}
|
}
|
||||||
@ -206,12 +215,21 @@ fn encodable_body(
|
|||||||
variant_idx += 1;
|
variant_idx += 1;
|
||||||
result
|
result
|
||||||
});
|
});
|
||||||
|
if variant_idx < u8::MAX as usize {
|
||||||
|
quote! {
|
||||||
|
let disc = match *self {
|
||||||
|
#encode_inner
|
||||||
|
};
|
||||||
|
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
quote! {
|
quote! {
|
||||||
let disc = match *self {
|
let disc = match *self {
|
||||||
#encode_inner
|
#encode_inner
|
||||||
};
|
};
|
||||||
::rustc_serialize::Encoder::emit_usize(__encoder, disc);
|
::rustc_serialize::Encoder::emit_usize(__encoder, disc);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut variant_idx = 0usize;
|
let mut variant_idx = 0usize;
|
||||||
|
Loading…
Reference in New Issue
Block a user