Skip to content

Commit

Permalink
Remove some clones of names of things
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Aug 6, 2023
1 parent e3617e1 commit da55ed7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
10 changes: 5 additions & 5 deletions serde_derive/src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ fn deserialize_struct(
} else {
let field_names = field_names_idents
.iter()
.flat_map(|(_, _, aliases)| aliases);
.flat_map(|&(_, _, aliases)| aliases);

Some(quote! {
#[doc(hidden)]
Expand Down Expand Up @@ -1162,7 +1162,7 @@ fn deserialize_struct_in_place(
let visit_map = Stmts(deserialize_map_in_place(params, fields, cattrs));
let field_names = field_names_idents
.iter()
.flat_map(|(_, _, aliases)| aliases);
.flat_map(|&(_, _, aliases)| aliases);
let type_name = cattrs.name().deserialize_name();

let in_place_impl_generics = de_impl_generics.in_place();
Expand Down Expand Up @@ -2001,7 +2001,7 @@ fn deserialize_untagged_newtype_variant(
}

fn deserialize_generated_identifier(
fields: &[(String, Ident, Vec<String>)],
fields: &[(&str, Ident, &[String])],
cattrs: &attr::Container,
is_variant: bool,
other_idx: Option<usize>,
Expand Down Expand Up @@ -2131,7 +2131,7 @@ fn deserialize_custom_identifier(
})
.collect();

let names = names_idents.iter().flat_map(|(_, _, aliases)| aliases);
let names = names_idents.iter().flat_map(|&(_, _, aliases)| aliases);

let names_const = if fallthrough.is_some() {
None
Expand Down Expand Up @@ -2187,7 +2187,7 @@ fn deserialize_custom_identifier(

fn deserialize_identifier(
this_value: &TokenStream,
fields: &[(String, Ident, Vec<String>)],
fields: &[(&str, Ident, &[String])],
is_variant: bool,
fallthrough: Option<TokenStream>,
fallthrough_borrowed: Option<TokenStream>,
Expand Down
16 changes: 8 additions & 8 deletions serde_derive/src/internals/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,17 @@ impl Name {
}

/// Return the container name for the container when serializing.
pub fn serialize_name(&self) -> String {
self.serialize.clone()
pub fn serialize_name(&self) -> &str {
&self.serialize
}

/// Return the container name for the container when deserializing.
pub fn deserialize_name(&self) -> String {
self.deserialize.clone()
pub fn deserialize_name(&self) -> &str {
&self.deserialize
}

fn deserialize_aliases(&self) -> Vec<String> {
self.deserialize_aliases.clone()
fn deserialize_aliases(&self) -> &[String] {
&self.deserialize_aliases
}

fn insert_deserialize_name_into_aliases(&mut self) {
Expand Down Expand Up @@ -986,7 +986,7 @@ impl Variant {
&self.name
}

pub fn aliases(&self) -> Vec<String> {
pub fn aliases(&self) -> &[String] {
self.name.deserialize_aliases()
}

Expand Down Expand Up @@ -1326,7 +1326,7 @@ impl Field {
&self.name
}

pub fn aliases(&self) -> Vec<String> {
pub fn aliases(&self) -> &[String] {
self.name.deserialize_aliases()
}

Expand Down
18 changes: 9 additions & 9 deletions serde_derive/src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ fn serialize_externally_tagged_variant(
},
params,
&variant.fields,
&type_name,
type_name,
),
}
}
Expand Down Expand Up @@ -631,7 +631,7 @@ fn serialize_internally_tagged_variant(
StructVariant::InternallyTagged { tag, variant_name },
params,
&variant.fields,
&type_name,
type_name,
),
Style::Tuple => unreachable!("checked in serde_derive_internals"),
}
Expand Down Expand Up @@ -698,7 +698,7 @@ fn serialize_adjacently_tagged_variant(
StructVariant::Untagged,
params,
&variant.fields,
&variant_name,
variant_name,
),
}
});
Expand Down Expand Up @@ -794,16 +794,16 @@ fn serialize_untagged_variant(
Style::Tuple => serialize_tuple_variant(TupleVariant::Untagged, params, &variant.fields),
Style::Struct => {
let type_name = cattrs.name().serialize_name();
serialize_struct_variant(StructVariant::Untagged, params, &variant.fields, &type_name)
serialize_struct_variant(StructVariant::Untagged, params, &variant.fields, type_name)
}
}
}

enum TupleVariant {
enum TupleVariant<'a> {
ExternallyTagged {
type_name: String,
type_name: &'a str,
variant_index: u32,
variant_name: String,
variant_name: &'a str,
},
Untagged,
}
Expand Down Expand Up @@ -870,11 +870,11 @@ fn serialize_tuple_variant(
enum StructVariant<'a> {
ExternallyTagged {
variant_index: u32,
variant_name: String,
variant_name: &'a str,
},
InternallyTagged {
tag: &'a str,
variant_name: String,
variant_name: &'a str,
},
Untagged,
}
Expand Down

0 comments on commit da55ed7

Please sign in to comment.