New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: String::replace_in_place #56415

clarcharr opened this Issue Dec 1, 2018 · 3 comments


None yet
4 participants

clarcharr commented Dec 1, 2018

Essentially, this can avoid allocating extra memory under the condition that the replacement is smaller than the searched expression. If the replacement is larger, a VecDeque<u8> can be kept to minimise the amount of extra bytes allocated. We could also pre-allocate an array on the stack and do some sort of SmallVecDeque.

Having a String::replace_in_place could also allow a Cow::replace_in_place which only allocates a new string if there's a change.

I'm cool providing a PR for this but I figured I'd post this here anyway, as a tracking issue will be needed anyway.


This comment has been minimized.


Centril commented Dec 3, 2018

Writing up a PR would be a good way to see the specifics and let T-libs see if they want it for the standard library or not.


This comment has been minimized.


clarcharr commented Dec 3, 2018

Yep! That's the plan. :)

I mostly just created this issue as a reminder for myself, considering how as I said a tracking issue would be needed anyway.


This comment has been minimized.


frewsxcv commented Dec 3, 2018

Somewhat similar, I opened an issue earlier this year for String::remove_matches which is intended to remove a Pattern from a String without allocating

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment