forked from mono/mono
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug mono#311: On LinkedList.Clear, detach each node instead of dr…
…opping them en masse.
- Loading branch information
Todd Foster
committed
Aug 17, 2011
1 parent
57bfe64
commit e787a12
Showing
2 changed files
with
7 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
e787a12
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any particular reason you used RemoveLast() instead of RemoveFirst()?
e787a12
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that you should be using Remove() instead of either RemoveFirst() or RemoveLast(), since you've already checked that first != null.
e787a12
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the most performant solution would be:
while (first != null)
Remove (first.back);
I'm guessing you chose RemoveLast() due to RemoveFirst() incurring an extra assignment per loop than RemoveLast().
e787a12
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct: I used RemoveLast to possibly avoid an extra assignment.
I chose to use RemoveLast() instead of Remove(first.back) because it was there (DRY). Let it take care of any housekeeping or optimization, including any future code changes.