Skip to content
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

Specialize into_heap() for Vec<T> when T is simple #41

Open
jorendorff opened this issue Sep 1, 2017 · 0 comments
Open

Specialize into_heap() for Vec<T> when T is simple #41

jorendorff opened this issue Sep 1, 2017 · 0 comments

Comments

@jorendorff
Copy link
Owner

jorendorff commented Sep 1, 2017

Specialization isn't stable in Rust yet, but we can specialize the old-fashioned way: use the mighty if.

One of the IntoHeap traits should have a static method is_trivial() which, if true, means we can move a Vec<T> into the heap without copying the buffer. It's probably OK whenever Self::In=Self, so, for machine types, tuples of trivial types, structs and enums with all trivial fields...

Then the into_heap method for Vec<T> can just ask. The branch will be inlined away.

(It's probably UB to use that trick on a Vec<FooRef<'h>> to turn it into a Vec<Pointer<Foo>>, but maybe that shouldn't stop us.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant