Conversation
…the String without an unnecessary allocation when it's already `Cow::Owned`
thomas-zahner
approved these changes
Sep 4, 2025
Member
thomas-zahner
left a comment
There was a problem hiding this comment.
I think this is an improvement as it doesn't increase complexity very much 👍
Member
|
Should this todo also be changed? lychee/lychee-lib/src/utils/request.rs Lines 115 to 120 in d6b16bc |
This was referenced Oct 21, 2025
Closed
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Out of curiosity, I finally tackled this TODO from the code:
// TODO: consider using Cow (to avoid one .clone() for String types)I took a look and it turns out it doesn't touch as many places as I thought it would, so I went with it.
The result is lesser allocations for places where we handle raw input strings.
I did add a micro-benchmark for input content creation and it turns out to be decently fast.
On my machine:
Not earth-shaking, but we're already operating at a decent level of performance by now, so I take it.
The question is: what do y'all think? Does it make the code too complex or is the complexity manageable? Feedback very welcome!