⚡ Bolt: Remove redundant String clones in redaction rules#623
Conversation
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
|
👋 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. |
There was a problem hiding this comment.
Code Review
This pull request optimizes string allocations in src/redaction.rs by storing &str references instead of owned Strings in literal_entries and literal_index_map, deferring cloning until necessary. A review comment correctly points out that the check seen_literals.contains(literal) is redundant because literal_entries is already deduplicated prior to the loop, making the lookup unnecessary.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| if seen_literals.contains(literal) { | ||
| continue; | ||
| } | ||
| seen_literals.insert(literal.to_owned()); |
There was a problem hiding this comment.
Since literal_entries is already deduplicated using literal_index_map (lines 171-182), all keys in literal_entries are guaranteed to be unique. Because seen_literals is empty before this loop and only populated within it, seen_literals.contains(literal) will always evaluate to false. Therefore, this check is redundant and can be safely removed to avoid unnecessary B-Tree lookups.
seen_literals.insert(literal.to_owned());
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## trunk #623 +/- ##
=======================================
Coverage 85.40% 85.40%
=======================================
Files 116 116
Lines 67035 67037 +2
=======================================
+ Hits 57250 57253 +3
+ Misses 9785 9784 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
💡 What: Updated
literal_index_mapandliteral_entriesto use string slice references (&str) instead of ownedStringinstances during the deduplication phase. Also addedseen_literals.contains(&literal)checks to prevent cloning the literal string when the set already contains it.🎯 Why: To prevent unnecessary heap allocations when iterating and deduplicating secret literals.
📊 Impact: Eliminates redundant
.clone()calls, reducing memory allocations on the redaction initialization hot path.🔬 Measurement: Verified correctness via
cargo test --lib redaction.PR created automatically by Jules for task 14438193805074593971 started by @madmax983