Skip to content

Commit 3adba15

Browse files
committed
removed unnecessary allocations and annotations
1 parent 397c367 commit 3adba15

File tree

2 files changed

+7
-52
lines changed

2 files changed

+7
-52
lines changed

node-graph/node-macro/src/destruct.rs

Lines changed: 6 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use convert_case::{Case, Casing};
22
use proc_macro_crate::FoundCrate;
33
use proc_macro2::{Span, TokenStream as TokenStream2};
44
use quote::{format_ident, quote};
5-
use syn::{Data, DeriveInput, Error, LitStr, Meta, Type, spanned::Spanned};
5+
use syn::{Data, DeriveInput, Error, LitStr, Type, spanned::Spanned};
66

77
pub fn derive(input: DeriveInput) -> syn::Result<TokenStream2> {
88
let struct_name = input.ident;
@@ -31,7 +31,7 @@ pub fn derive(input: DeriveInput) -> syn::Result<TokenStream2> {
3131
};
3232

3333
let ty = field.ty;
34-
let output_name = parse_output_name(&field.attrs)?.unwrap_or_else(|| field_name.to_string().to_case(Case::Title));
34+
let output_name = field_name.to_string().to_case(Case::Title);
3535
let output_name_lit = LitStr::new(&output_name, field_name.span());
3636

3737
let fn_name = format_ident!("extract_{}_{}", struct_name.to_string().to_case(Case::Snake), field_name);
@@ -52,63 +52,20 @@ pub fn derive(input: DeriveInput) -> syn::Result<TokenStream2> {
5252

5353
impl #impl_generics #core_types::registry::Destruct for #struct_name #ty_generics #where_clause {
5454
fn fields() -> &'static [#core_types::registry::StructField] {
55-
static FIELDS: std::sync::OnceLock<Vec<#core_types::registry::StructField>> = std::sync::OnceLock::new();
56-
FIELDS.get_or_init(|| vec![
55+
const FIELDS: &[#core_types::registry::StructField] = &[
5756
#(#output_fields,)*
58-
]).as_slice()
57+
];
58+
FIELDS
5959
}
6060
}
6161
})
6262
}
6363

6464
fn generate_extractor_node(core_types: &TokenStream2, fn_name: &syn::Ident, struct_name: &syn::Ident, field_name: &syn::Ident, ty: &Type, output_name: &LitStr) -> TokenStream2 {
6565
quote! {
66-
#[node_macro::node(category(""), name(#output_name))]
66+
#[node_macro::node(category(""))]
6767
fn #fn_name(_: impl #core_types::Ctx, data: #struct_name) -> #ty {
6868
data.#field_name
6969
}
7070
}
7171
}
72-
73-
fn parse_output_name(attrs: &[syn::Attribute]) -> syn::Result<Option<String>> {
74-
let mut output_name = None;
75-
76-
for attr in attrs {
77-
if !attr.path().is_ident("output") {
78-
continue;
79-
}
80-
81-
let mut this_output_name = None;
82-
match &attr.meta {
83-
Meta::Path(_) => {
84-
return Err(Error::new_spanned(attr, "Expected output metadata like #[output(name = \"Result\")]"));
85-
}
86-
Meta::NameValue(_) => {
87-
return Err(Error::new_spanned(attr, "Expected output metadata like #[output(name = \"Result\")]"));
88-
}
89-
Meta::List(_) => {
90-
attr.parse_nested_meta(|meta| {
91-
if meta.path.is_ident("name") {
92-
if this_output_name.is_some() {
93-
return Err(meta.error("Multiple output names provided for one field"));
94-
}
95-
let value = meta.value()?;
96-
let lit: LitStr = value.parse()?;
97-
this_output_name = Some(lit.value());
98-
Ok(())
99-
} else {
100-
Err(meta.error("Unsupported output metadata. Supported syntax is #[output(name = \"...\")]"))
101-
}
102-
})?;
103-
}
104-
}
105-
106-
let this_output_name = this_output_name.ok_or_else(|| Error::new_spanned(attr, "Missing output name. Use #[output(name = \"...\")]"))?;
107-
if output_name.is_some() {
108-
return Err(Error::new_spanned(attr, "Multiple #[output(...)] attributes are not allowed on one field"));
109-
}
110-
output_name = Some(this_output_name);
111-
}
112-
113-
Ok(output_name)
114-
}

node-graph/preprocessor/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ pub fn generate_node_substitutions() -> HashMap<ProtoNodeIdentifier, DocumentNod
115115
let available_output_fields: Vec<_> = output_fields
116116
.iter()
117117
.filter_map(|field| {
118-
let identifier = ProtoNodeIdentifier::with_owned_string(field.node_path.to_string());
118+
let identifier = ProtoNodeIdentifier::new(field.node_path);
119119
if node_registry.contains_key(&identifier) {
120120
Some((field, identifier))
121121
} else {
@@ -161,7 +161,6 @@ pub fn generate_node_substitutions() -> HashMap<ProtoNodeIdentifier, DocumentNod
161161
inputs: vec![NodeInput::node(source_node_id, 0)],
162162
call_argument: input_type.clone(),
163163
implementation: DocumentNodeImplementation::ProtoNode(memo_node.clone()),
164-
visible: false,
165164
..Default::default()
166165
},
167166
);
@@ -191,7 +190,6 @@ pub fn generate_node_substitutions() -> HashMap<ProtoNodeIdentifier, DocumentNod
191190
inputs: vec![NodeInput::node(output_source_node, 0)],
192191
call_argument: accessor_call_argument,
193192
implementation: DocumentNodeImplementation::ProtoNode(field_identifier.clone()),
194-
visible: false,
195193
..Default::default()
196194
},
197195
);

0 commit comments

Comments
 (0)