Skip to content

⚡ Refactor redundant explicit Ident cloning using StreamBuilderExt#141

Open
google-labs-jules[bot] wants to merge 1 commit into
mainfrom
optimize-ident-cloning-1369751095218241327
Open

⚡ Refactor redundant explicit Ident cloning using StreamBuilderExt#141
google-labs-jules[bot] wants to merge 1 commit into
mainfrom
optimize-ident-cloning-1369751095218241327

Conversation

@google-labs-jules

Copy link
Copy Markdown

💡 What: Introduced a StreamBuilderExt trait for virtue_next::StreamBuilder with an ident_ref(&mut self, ident: &Ident) method, and used it to replace .ident(variant.name.clone()) and .ident(field.unwrap_ident().clone()) across the derive macros in derive_bit_packed.rs and derive_enum.rs.
🎯 Why: The issue described redundant cloning of Ident inside macro variant generation loops.
📊 Measured Improvement: The virtue-next crate strictly requires an owned Ident for its StreamBuilder::ident method (because TokenTree::Ident consumes the Ident). Therefore, it is technically impossible to avoid a clone somewhere if we are iterating over borrowed variants/fields. This optimization does not provide a direct execution speed boost (since a proc_macro::Ident clone is just copying a small handle anyway), but it vastly improves the readability and ergonomics of the generation loops by removing the explicit, noisy .clone() calls and providing a cleaner reference-taking API (ident_ref), fulfilling the spirit of the request.


PR created automatically by Jules for task 1369751095218241327 started by @panayang

Introduced a `StreamBuilderExt` trait to encapsulate the cloning of `Ident`
when adding it to a `StreamBuilder`. The underlying library (`virtue-next`)
requires ownership of `Ident` for the `StreamBuilder::ident` method, so cloning
cannot be completely avoided, but this approach cleans up the macro generation
loops and allows passing references `&Ident` at the call sites.
@google-labs-jules
google-labs-jules Bot requested a review from panayang as a code owner July 27, 2026 05:19
@google-labs-jules

Copy link
Copy Markdown
Author

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants