-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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] Ability to reserve String
capacity directly
#3738
Comments
Also I think it will be fitting to add a I think we also need to implement
I'd rather reduce the amount of head-space people need to use the stdlib |
@martinvuyk Yep, I share the exact same thoughts! |
…to the String struct (#50557) [External] [stdlib] Addition of a new constructor and reserve method to the String struct Adds a public API for users to allocate capacity through String, instead of having to reach into the private internal `._buffer` attribute. Satisfies: #3738 Co-authored-by: Mikhail Tavarez <[email protected]> Closes #3755 MODULAR_ORIG_COMMIT_REV_ID: 3d3c3c4fd49acaf3f8f204e453039bacfe57a8ac
This change was merged into the nightly branch, closing the issue. |
Thank you! Looks like "satisfies" in 55cbae5 didn't close the issue. Typically I use "Fixes" or "Closes" which is respected by the GitHub automation. |
Ah, I didn't know there was automation around that! I'll keep that in mind for the future 🙂 |
No worries. Yeah, see https://github.blog/news-insights/product-news/closing-issues-via-commit-messages/. Old blog post but hasn't changed much I suspect. |
There's a fair bit of cleanup work we could do now to leverage the new constructor throughout the stdlib. This would have the benefit of less reaching into private data members, which is always a plus. |
…to the String struct (#50557) [External] [stdlib] Addition of a new constructor and reserve method to the String struct Adds a public API for users to allocate capacity through String, instead of having to reach into the private internal `._buffer` attribute. Satisfies: #3738 Co-authored-by: Mikhail Tavarez <[email protected]> Closes #3755 MODULAR_ORIG_COMMIT_REV_ID: 3d3c3c4fd49acaf3f8f204e453039bacfe57a8ac
Review Mojo's priorities
What is your request?
As the title says, I'd like to see what the community thinks about introducing a public API to allocate String capacity ala something like
my_string.reserve(new_capacity=1000)
?What is your motivation for this change?
I had a use case where I was treating a
String
as a buffer so I could write bytes to it, where I roughly knew what the capacity would be ahead of time. Maybe having aStringBuilder
struct would be better than usingString
for this purpose?This is a continuation of the conversation started on this PR: #3735 (comment)
Any other details?
No response
The text was updated successfully, but these errors were encountered: