-
Notifications
You must be signed in to change notification settings - Fork 5
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
ensure len and capacity methods reflect their intentions #4
base: master
Are you sure you want to change the base?
Conversation
The implementation of I opened #5 suitable for a minor bugfix release, but I agree that |
@neevek See discussion at async-email/async-imap#77 (comment), maybe it is not needed to have additional method because poolable vector is supposed to have exactly the same length and capacity all the time. I don't know what is the idea about HashMap though, we definitely cannot pre-fill it with default values as we cannot generate "default keys". @flub Maybe we drop HashMap support completely, is anyone using it? It is inconsistent with what Vec does, because it reallocates capacity while Poolable::capacity() looks at the length. Maybe we better focus this crate at allocating Vec only or even Vec only. |
src/poolable.rs
Outdated
fn alloc(size: usize) -> Self { | ||
vec![T::default(); size] | ||
Vec::<T>::with_capacity(size) |
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.
This changes semantics quite a bit and breaks len == capacity invariant mentioned in async-email/async-imap#77 (comment)
I think this line should be reverted.
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 agree that this completely changes the original semantics, and that indeed will break code that uses the crate.
How about adding another alloc function that only reserves the requested size of memory, and doesn't fill the buffer with default values, which makes len
work the way I intended, for example adding a reserve
associated function, code that relies on alloc
are not affected, and new code can choose to use alloc
or reserve
.
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.
If that is okay, we can keep the implementation of the Realloc
trait unchanged, and add a Reserve
trait that provides a reserve
function for poolable objects, or maybe we don't even need to do that since only Vec
is used as poolable object.
@link2xt I use byte-pool as an alternative to |
No description provided.