Skip to content

LinkedList: Incremental improvements #26050

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

Merged
merged 5 commits into from
Jun 6, 2015
Merged

Conversation

bluss
Copy link
Member

@bluss bluss commented Jun 6, 2015

The recent bug that was found in LinkedList reminded me of some general cleanup
that's been waiting for some time.

  • Use a loop from the front in Drop, it works just as well and without an unsafe block
  • Change Rawlink methods to use unsafe in an idiomatic way. This does mean that
    we need an unsafe block for each dereference of a raw link. Even then, the extent
    of unsafe-critical code is even larger of course, since safety depends on the whole
    data structure's integrity. This is a general problem we are aware of.
  • Some cleanup just to try to decrease the amount of Rawlink handling.

@rust-highfive
Copy link
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@bluss
Copy link
Member Author

bluss commented Jun 6, 2015

r? @gankro

Probably best reviewed commit by commit.

@rust-highfive rust-highfive assigned Gankra and unassigned alexcrichton Jun 6, 2015
@bluss bluss force-pushed the linked-list branch 3 times, most recently from f7bce33 to 55ad5f2 Compare June 6, 2015 12:24
@@ -609,12 +635,21 @@ impl<T> LinkedList<T> {
length: len - at
};

// Swap split_node.next with list_head (which is None), nulling out split_node.next,
// as it is the new tail.
mem::swap(&mut split_node.resolve().unwrap().next, &mut splitted_list.list_head);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this could have just been done in the ctor of splitted_list all along, right?

let mut splitted_list = LinkedList {
    list_head: split_node.resolve().unwrap().next.take(),
    list_tail: self.list_tail,
    length: len - at,
}

@bluss
Copy link
Member Author

bluss commented Jun 6, 2015

I've updated split_off, it's sort of a compromise now (but I like it). Use .unwrap() in one place, but no map where it's just for side effects.

@bluss
Copy link
Member Author

bluss commented Jun 6, 2015

I'll squash that in later.

@bluss
Copy link
Member Author

bluss commented Jun 6, 2015

I couldn't help renaming splitted, I refuse this neologism.

second_part_head = split_node.resolve_mut().unwrap().next.take();
match second_part_head {
None => {}
Some(ref mut head) => head.prev = Rawlink::none(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just know someone's going to submit a PR for "replace match with if-let/map/unwrap", but I'm going to accept this ;)

@Gankra
Copy link
Contributor

Gankra commented Jun 6, 2015

r=me once you've done whatever squashing you feel is appropriate.

@bluss
Copy link
Member Author

bluss commented Jun 6, 2015

@bors: r=Gankro

@bors
Copy link
Collaborator

bors commented Jun 6, 2015

📌 Commit 32037a5 has been approved by Gankro

@bluss
Copy link
Member Author

bluss commented Jun 6, 2015

wheee!

bors added a commit that referenced this pull request Jun 6, 2015
The recent bug that was found in LinkedList reminded me of some general cleanup
that's been waiting for some time.

- Use a loop from the front in Drop, it works just as well and without an unsafe block
- Change Rawlink methods to use `unsafe` in an idiomatic way. This does mean that
we need an unsafe block for each dereference of a raw link. Even then, the extent
of unsafe-critical code is even larger of course, since safety depends on the whole
data structure's integrity. This is a general problem we are aware of.
- Some cleanup just to try to decrease the amount of Rawlink handling.
@bors
Copy link
Collaborator

bors commented Jun 6, 2015

⌛ Testing commit 32037a5 with merge 98f6e40...

@bors bors merged commit 32037a5 into rust-lang:master Jun 6, 2015
@bluss bluss deleted the linked-list branch June 6, 2015 21:47
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.

5 participants