Use into_owned() instead of to_string() on Cow<str>#152
Conversation
…_utf8_lossy Avoids going through the Display trait for the String conversion.
🤖 Kimi Code ReviewThe changes look good and are performance-oriented micro-optimizations:
Both changes are correct and idiomatic Rust. The These are safe, low-risk optimizations that improve performance without affecting correctness. Automated review by Kimi (Moonshot AI) · custom prompt |
🤖 Codex Code ReviewNo issues found in this diff. The change from I didn’t run tests. Automated review by OpenAI Codex · custom prompt |
🤖 Claude Code ReviewThe change is small, correct, and well-motivated. Here's the review: PR #152 Review: Use
|
Greptile SummaryOptimized String conversion from
Confidence Score: 5/5
|
| Filename | Overview |
|---|---|
| crates/net/p2p/src/req_resp/codec.rs | Replaced .to_string() with .into_owned() on Cow<str> for more efficient String conversion in error handling paths |
Last reviewed commit: 785cd22
There was a problem hiding this comment.
Pull request overview
This PR optimizes string conversions in the request/response codec by replacing .to_string() with .into_owned() when converting Cow<str> (returned by String::from_utf8_lossy()) to owned String. This avoids the overhead of going through the Display trait and directly obtains an owned string.
Changes:
- Replace
.to_string()with.into_owned()on twoCow<str>conversions in error message handling
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
.to_string()with.into_owned()onCow<str>returned byString::from_utf8_lossy()in the req/resp codecDisplaytrait for theStringconversioncrates/net/p2p/src/req_resp/codec.rs(lines 176 and 230)Test plan
cargo checkpasses