-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Introduce sizehint!(s, n; shrink = true) to controll shrinkage #51929
Introduce sizehint!(s, n; shrink = true) to controll shrinkage #51929
Conversation
LGTM. Thanks for working on this. |
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this need to promote it from draft?
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
…lia into pv/dict-controll-shrinkage-v3
Are CI problems related? I'll update branch to test. |
CI passes and PR seems ready. |
Rebased #51903 on top of this now. Thanks! |
@@ -1462,10 +1462,15 @@ For types that support `sizehint!`, | |||
`Base`. | |||
|
|||
3. `empty!` is nearly costless (and O(1)) for types that support this kind of preallocation. | |||
|
|||
4. `shrink` controls if the collection can be shrunk. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reading this, I don't understand what the argument does. Would you mind adding a more detailed explanation? Also it would seem more appropriate to mention the argument above, outside of the "# Notes on the performance model", as I wouldn't expect to have to read a performance section to find out the meaning of an argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this seems like a fair point. The new optional argument enables us to suggest not to shrink the already reserved capacity when suggesting new size by setting shrink = false
. This is helpful for algorithms like merging two collection where you want to pre-allocate memory, but there is not reason to change (shrink) size if all the data fits. I'm not a native speaker, would you be able to propose a more fitting description?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've not a native speaker either, but see #52226. I hope I got it right.
This is a second part of #51629 to introduce
shrink = true
argument forsizehint!
into public API. Fell free to propose a different name, or way to control shrinkage.Thinks to do:
Vector
Set
Vector
Set