`from_utf8_lossy_owned` is not done in-place
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Filing this for tracking reasons, since it is an area of the standard library that can be improved. from_utf8_lossy_owned is being stabilized soon so it does not make sense to put this in the existing issue.
Algorithmically I think this could be accomplished by:
- Iterate over chunks, counting the number of replacement characters needed.
- If no replacement characters are needed, return as-is.
- Allocate exact capacity for the additional replacement characters.
- In reverse, overlapping copy chunks to the end of the allocated capacity and push replacement characters when needed (this requires
Utf8Chunksto become aDoubleEndedIterator) - The Vec is now valid utf8. set_len and return.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the existing from_utf8_lossy_owned implementation and the Utf8Chunks iterator, then compare them with the stabilization work referenced in the issue. The change is done when valid input is returned as-is and invalid input is repaired in-place using exact additional capacity and reverse overlapping copies, with coverage for both paths.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- performance
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100