-
Notifications
You must be signed in to change notification settings - Fork 13k
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
add a small vector to the standard library #4991
Comments
Added the An-interesting-project label. |
@catamorphism @thestinger |
@abhijeetgaiha it's more subtle than that, it's effectively: enum SmallVector<T> {
Small(uint, [T, .. 8]), // size, data (the 8 shouldn't be hardcoded like this)
Big(uint, uint, *T) // capacity, size, pointer
} (But not exactly, a Rust implementation should try to leverage LLVM's support.) I.e. it is a value with size 3 words, and if there are a small number of elements they are stored directly in the value, not behind a pointer-indirection. |
@huonw: LLVM's type is just a templated C++ container that they use heavily throughout their codebase, it's not really useful to us. |
@huonw @thestinger Looks like you are suggesting we have the following struct For small values, we set big to false and re-use the space reserved for size, capacity and ptr for storage. Am I following you correctly? |
@abhijeetgaiha I think the best-case scenario would be (Note that you still need to indicate the size of the data when on the stack, so |
@huonw Thanks for the input. I'm going to make a initial attempt at this. |
This is still unimplemented and would be very useful, but the lack of integers in the type system makes the concept much less powerful. |
I just saw that there is a |
@erickt: It should be doing one branch for a small case (3+ words) and a large case and ideally avoiding the overhead of using an |
This need not block 1.0. @pcwalton has one in Servo that we could copy over if need be. Assigning P-low. |
CC #16998 as a sister effort |
clearly a feature request |
…1995 Add suggestions for `if_let_some_result` Fixes rust-lang#4991 This approach may be fragile though... changelog: Add suggestions for `if_let_some_result`
It's often useful to have a vector optimized for storing small sequences. LLVM includes a
SmallVector
templated type which takes the size to store inside the struct as a template parameter, which isn't possible at the moment in Rust. However, it would be fine to just copy what libc++ does forstd::string
which is to store 3 words in the struct (size, capacity, and the pointer) and reuse that space for the small string optimization.The text was updated successfully, but these errors were encountered: