chore: reduce duplication and unnecessary allocations - #495
Conversation
DRY improvements: - Extract signal_err() helper for 12+ identical .map_err() patterns in signal_adapter.rs - Extract flush_signal_cache_logged() for 6 identical if-let-Err logging patterns across send.rs, message.rs, notification.rs, device_registry.rs, retry.rs - Extract setup_lid_pn() and setup_device_record() test helpers in device_registry.rs, replacing 17 duplicated fixture blocks Allocation reductions: - Use .take() instead of .clone() for device snapshot fields in send paths (pn, lid, account) — moves owned data instead of copying - Hoist own_jid.to_string() before participant loop in message.rs and keep Cow<str> from optional_string() as-is for zero-copy comparison
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (7)
📝 WalkthroughWalkthroughThis pull request introduces a helper method Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@claude review |
|
Claude finished @jlucaso1's task in 1m 4s —— View job Code Review:
|
Summary
-177 lines net across 7 files. No behavior changes.
DRY improvements
signal_err()helper (signal_adapter.rs): Replaces 12 identical.map_err(|e| SignalProtocolError::InvalidState("...", e.to_string()))patterns with.map_err(signal_err("..."))flush_signal_cache_logged()(client.rs): Replaces 6 identical if-let-Err logging blocks acrosssend.rs,message.rs,notification.rs,device_registry.rs,retry.rsdevice_registry.rs):setup_lid_pn()andsetup_device_record()replace 17 duplicated fixture setup blocksAllocation reductions
.take()instead of.clone()on device snapshot fields (send.rs): Movespn,lid,accountout of the owned snapshot instead of cloning — eliminates 6 clone calls across 2 send pathsmessage.rs): Hoistsown_jid.to_string()before the loop, keepsCow<str>fromoptional_string()as-is for direct&strcomparison — eliminates 2 allocations per participant per messageTest plan
cargo test --workspace --exclude e2e-tests— all tests passSummary by CodeRabbit