Skip to content

Remove redundant heap allocation in DisplayablePathBuf::from_string#336

Merged
DHowett merged 4 commits into
microsoft:mainfrom
rhysd:remove-redundant-heap-alloc
Jun 4, 2025
Merged

Remove redundant heap allocation in DisplayablePathBuf::from_string#336
DHowett merged 4 commits into
microsoft:mainfrom
rhysd:remove-redundant-heap-alloc

Conversation

@rhysd

@rhysd rhysd commented May 28, 2025

Copy link
Copy Markdown
Contributor

DisplayablePathBuf::from_string allocates two heap memories for PathBuf and Cow::Owned. However it can be stored as Cow::Borrowed because String guarantees UTF-8 sequence. This can remove one redundant heap allocation. As a bonus DisplayablePathBuf::from_path can be reused so the code is more simplified.

Comment thread src/bin/edit/state.rs Outdated
@rhysd

rhysd commented May 30, 2025

Copy link
Copy Markdown
Contributor Author

@lhecker I addressed the comment and force-pushed the commit. Would you take a look again? I apoligize for the delay.

@lhecker
lhecker requested a review from DHowett May 30, 2025 11:57

@DHowett DHowett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@DHowett
DHowett merged commit 795f576 into microsoft:main Jun 4, 2025
Lou32Verbose pushed a commit to Lou32Verbose/edit that referenced this pull request Jan 11, 2026
…microsoft#336)

`DisplayablePathBuf::from_string` allocates two heap memories for
`PathBuf` and `Cow::Owned`. However, it can be stored as `Cow::Borrowed`
because `String` guarantees UTF-8 sequence. This can remove one
redundant heap allocation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants