Skip to content
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

Open
clarfonthey opened this issue Dec 1, 2018 · 7 comments
Open

Feature request: String::replace_in_place #56415

clarfonthey opened this issue Dec 1, 2018 · 7 comments
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@clarfonthey
Copy link
Contributor

clarfonthey 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 don't have the time for this but I figured I'd post this here anyway, as a tracking issue will be needed anyway.

@kennytm kennytm added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Dec 1, 2018
@Centril Centril added the C-feature-request Category: A feature request, i.e: not implemented / a PR. label Dec 2, 2018
@Centril
Copy link
Contributor

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.

@clarfonthey
Copy link
Contributor Author

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.

@frewsxcv
Copy link
Member

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

@kevincox
Copy link
Contributor

I think that replace_in_place is more general then the remove_matches since the latter is simply replacing with "".

@golddranks
Copy link
Contributor

golddranks commented Feb 7, 2020

@frewsxcv or @clarfon, are you planning on working this feature? I'm interested in getting it done too.

@frewsxcv
Copy link
Member

frewsxcv commented Feb 8, 2020

@frewsxcv or @clarfon, are you planning on working this feature? I'm interested in getting it done too.

I'm not planning to work it

@clarfonthey
Copy link
Contributor Author

I don't have time at the moment but I'm fine with someone else picking it up. Will modify the OP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants