Skip to content

Commit

Permalink
perf: Remove unneeded cloning
Browse files Browse the repository at this point in the history
  • Loading branch information
GrayJack committed Jan 15, 2025
1 parent 473d2c8 commit b02859d
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions bitflags-attr-macros/src/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@ impl Bitflag {

let item: ItemEnum = syn::parse(item)?;
let item_span = item.span();
let og_attrs: Vec<Attribute> = item
let og_attrs = item
.attrs
.iter()
.filter(|att| !att.path().is_ident("extra_valid_bits"))
.cloned()
.collect();
.filter(|att| !att.path().is_ident("extra_valid_bits"));

let vis = item.vis;
let name = item.ident;
Expand All @@ -50,11 +48,11 @@ impl Bitflag {
// Attributes
let attrs = item
.attrs
.clone()
.into_iter()
.iter()
.filter(|att| {
!att.path().is_ident("derive") && !att.path().is_ident("extra_valid_bits")
})
.cloned()
.collect();

let valid_bits_attr = item
Expand All @@ -64,8 +62,7 @@ impl Bitflag {

let derives = item
.attrs
.clone()
.into_iter()
.iter()
.filter(|att| att.path().is_ident("derive"));

let mut derived_traits = Vec::new();
Expand Down Expand Up @@ -154,16 +151,14 @@ impl Bitflag {
}
};

let non_doc_attrs = var_attrs
.clone()
.into_iter()
let non_doc_attrs: Vec<Attribute> = var_attrs
.iter()
.filter(|attr| !attr.path().is_ident("doc"))
.collect::<Vec<syn::Attribute>>();
.cloned()
.collect();

all_flags.push(quote!(Self::#var_name));
// all_flags_names.push(quote!(stringify!(#var_name)));
all_flags_names.push(syn::LitStr::new(&var_name.to_string(), var_name.span()));
// all_variants.push(var_name.clone());
all_variants.push(var_name.clone());
all_attrs.push(non_doc_attrs.clone());
raw_flags.push(quote! {
Expand Down

0 comments on commit b02859d

Please sign in to comment.