mirror of
https://github.com/serde-rs/serde.git
synced 2025-10-02 15:25:38 +00:00
Slightly reduced number of allocations
This commit is contained in:
parent
78fea3aa4a
commit
7ca7720262
@ -2221,16 +2221,14 @@ fn deserialize_identifier(
|
|||||||
flat_fields.extend(aliases.iter().map(|alias| (alias, ident)));
|
flat_fields.extend(aliases.iter().map(|alias| (alias, ident)));
|
||||||
}
|
}
|
||||||
|
|
||||||
let field_strs: &Vec<_> = &flat_fields.iter().map(|(name, _)| name).collect();
|
let str_mapping = flat_fields.iter().map(|(name, ident)| {
|
||||||
let field_bytes: &Vec<_> = &flat_fields
|
quote!(#name => _serde::__private::Ok(#this_value::#ident))
|
||||||
.iter()
|
});
|
||||||
.map(|(name, _)| Literal::byte_string(name.as_bytes()))
|
let bytes_mapping = flat_fields.iter().map(|(name, ident)| {
|
||||||
.collect();
|
let name = Literal::byte_string(name.as_bytes());
|
||||||
|
quote!(#name => _serde::__private::Ok(#this_value::#ident))
|
||||||
|
});
|
||||||
|
|
||||||
let constructors: &Vec<_> = &flat_fields
|
|
||||||
.iter()
|
|
||||||
.map(|(_, ident)| quote!(#this_value::#ident))
|
|
||||||
.collect();
|
|
||||||
let main_constructors: &Vec<_> = &fields
|
let main_constructors: &Vec<_> = &fields
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(_, ident, _)| quote!(#this_value::#ident))
|
.map(|(_, ident, _)| quote!(#this_value::#ident))
|
||||||
@ -2416,6 +2414,8 @@ fn deserialize_identifier(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let visit_borrowed = if fallthrough_borrowed.is_some() || collect_other_fields {
|
let visit_borrowed = if fallthrough_borrowed.is_some() || collect_other_fields {
|
||||||
|
let str_mapping = str_mapping.clone();
|
||||||
|
let bytes_mapping = bytes_mapping.clone();
|
||||||
let fallthrough_borrowed_arm = fallthrough_borrowed.as_ref().unwrap_or(fallthrough_arm);
|
let fallthrough_borrowed_arm = fallthrough_borrowed.as_ref().unwrap_or(fallthrough_arm);
|
||||||
Some(quote! {
|
Some(quote! {
|
||||||
fn visit_borrowed_str<__E>(self, __value: &'de str) -> _serde::__private::Result<Self::Value, __E>
|
fn visit_borrowed_str<__E>(self, __value: &'de str) -> _serde::__private::Result<Self::Value, __E>
|
||||||
@ -2423,9 +2423,7 @@ fn deserialize_identifier(
|
|||||||
__E: _serde::de::Error,
|
__E: _serde::de::Error,
|
||||||
{
|
{
|
||||||
match __value {
|
match __value {
|
||||||
#(
|
#(#str_mapping,)*
|
||||||
#field_strs => _serde::__private::Ok(#constructors),
|
|
||||||
)*
|
|
||||||
_ => {
|
_ => {
|
||||||
#value_as_borrowed_str_content
|
#value_as_borrowed_str_content
|
||||||
#fallthrough_borrowed_arm
|
#fallthrough_borrowed_arm
|
||||||
@ -2438,9 +2436,7 @@ fn deserialize_identifier(
|
|||||||
__E: _serde::de::Error,
|
__E: _serde::de::Error,
|
||||||
{
|
{
|
||||||
match __value {
|
match __value {
|
||||||
#(
|
#(#bytes_mapping,)*
|
||||||
#field_bytes => _serde::__private::Ok(#constructors),
|
|
||||||
)*
|
|
||||||
_ => {
|
_ => {
|
||||||
#bytes_to_str
|
#bytes_to_str
|
||||||
#value_as_borrowed_bytes_content
|
#value_as_borrowed_bytes_content
|
||||||
@ -2465,9 +2461,7 @@ fn deserialize_identifier(
|
|||||||
__E: _serde::de::Error,
|
__E: _serde::de::Error,
|
||||||
{
|
{
|
||||||
match __value {
|
match __value {
|
||||||
#(
|
#(#str_mapping,)*
|
||||||
#field_strs => _serde::__private::Ok(#constructors),
|
|
||||||
)*
|
|
||||||
_ => {
|
_ => {
|
||||||
#value_as_str_content
|
#value_as_str_content
|
||||||
#fallthrough_arm
|
#fallthrough_arm
|
||||||
@ -2480,9 +2474,7 @@ fn deserialize_identifier(
|
|||||||
__E: _serde::de::Error,
|
__E: _serde::de::Error,
|
||||||
{
|
{
|
||||||
match __value {
|
match __value {
|
||||||
#(
|
#(#bytes_mapping,)*
|
||||||
#field_bytes => _serde::__private::Ok(#constructors),
|
|
||||||
)*
|
|
||||||
_ => {
|
_ => {
|
||||||
#bytes_to_str
|
#bytes_to_str
|
||||||
#value_as_bytes_content
|
#value_as_bytes_content
|
||||||
|
Loading…
x
Reference in New Issue
Block a user