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

Remove unnecessary .take() calls in Rust #84

Merged
merged 1 commit into from
Apr 8, 2020
Merged

Conversation

CryZe
Copy link
Contributor

@CryZe CryZe commented Apr 8, 2020

These are not necessary because the compiler can statically reason about temporary "uninitialized" variables. Unfortunately this doesn't work for self.root in the Tree methods, as there the uninitialized memory could be perceivable when those methods panic.

Looking at the assembly, this removes some unnecessary drop calls, so this should result in a slight speedup.

These are not necessary because the compiler can statically reason about temporary "uninitialized" variables. Unfortunately this doesn't work for self.root in the Tree methods, as there the uninitialized memory could be perceivable when those methods panic.

Looking at the assembly, this removes some unnecessary drop calls, so this should result in a slight speedup.
@frol frol merged commit d2d276c into frol:master Apr 8, 2020
@frol
Copy link
Owner

frol commented Apr 8, 2020

Wow, this improved the performance noticeably! We are down from 0.315s to 0.230s!

This was not possible in Rust 1.26 (before NLL, with the old borrow checker)!

error[E0382]: use of partially moved value: `lower_node`
  --> src/idiomatic_impl.rs:31:17
   |
31 |                 lower_node.right = merge(lower_node.right, Some(greater_node));
   |                 ^^^^^^^^^^^^^^^^^^^^^^^^^----------------^^^^^^^^^^^^^^^^^^^^^
   |                 |                        |
   |                 |                        value moved here
   |                 value used here after move
   |
   = note: move occurs because `lower_node.right` has type `std::option::Option<std::boxed::Box<idiomatic_impl::Node>>`, which does not implement the `Copy` trait

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

Successfully merging this pull request may close these issues.

2 participants