⚡ Refactor redundant explicit Ident cloning using StreamBuilderExt#141
⚡ Refactor redundant explicit Ident cloning using StreamBuilderExt#141google-labs-jules[bot] wants to merge 1 commit into
Conversation
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.
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
💡 What: Introduced a
StreamBuilderExttrait forvirtue_next::StreamBuilderwith anident_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 inderive_bit_packed.rsandderive_enum.rs.🎯 Why: The issue described redundant cloning of
Identinside macro variant generation loops.📊 Measured Improvement: The
virtue-nextcrate strictly requires an ownedIdentfor itsStreamBuilder::identmethod (becauseTokenTree::Identconsumes theIdent). 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 aproc_macro::Identclone 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