Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAvoid heap allocation for initial value of vector longhands which do not allow empty #15807
Labels
Comments
|
These should use |
|
That probably makes things more complicated. It should just be struct AutoVec<T> {
first: T,
rest: Vec<T>,
}and you can implement index trait on it. |
|
cc @emilio |
|
We have SmallVec for this purpose. |
|
I'm working on things that are similar to this. I think we should go for: enum ToBeNamed<T> {
Single(T),
Many(Box<[T]>),
}This is smaller than |
|
In the opposite direction, I just made this for properties that can be empty and have an empty initial value. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So far there are various vector longhands which have
allow_emptybeing false. The initial value of those properties would always need a heap allocation for the only element in the vector. This should be fixed.Gecko avoids this via having the first element stored inline. Servo can probably use this method as well.
cc @emilio @Manishearth