Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix bug #311: On LinkedList.Clear, detach each node instead of dropping them en masse. #161

Merged
merged 1 commit into from

4 participants

@toddfoster

No description provided.

@skolima

This is consistent with LinkedList.Clear having O(n) complexity: http://msdn.microsoft.com/en-us/library/wdcbyw41%28v=vs.80%29.aspx . So +1 from me for this patch.

@jstedfast
Owner

Any particular reason you used RemoveLast() instead of RemoveFirst()?

It seems that you should be using Remove() instead of either RemoveFirst() or RemoveLast(), since you've already checked that first != null.

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().

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.

@wwim wwim referenced this pull request from a commit in wwim/mono
@grendello grendello [runtime, globalization] Fix for Xamarin bug #161. Fix culture info d…
…ata for certain locale short date formats

Modified locales which don't use '/' as the short date separator.
ec0e9d7
@alanmcgovern alanmcgovern merged commit d23d8aa into from
@duarten duarten referenced this pull request from a commit in duarten/mono
@grendello grendello [runtime, globalization] Fix for Xamarin bug #161. Fix culture info d…
…ata for certain locale short date formats

Modified locales which don't use '/' as the short date separator.
ec2cfa6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 17, 2011
  1. Fix bug #311: On LinkedList.Clear, detach each node instead of droppi…

    Todd Foster authored
    …ng them en masse.
This page is out of date. Refresh to see the latest.
View
5 mcs/class/System/System.Collections.Generic/LinkedList.cs
@@ -182,9 +182,8 @@ public void AddLast (LinkedListNode <T> node)
public void Clear ()
{
- count = 0;
- first = null;
- version++;
+ while (first != null)
+ RemoveLast();
}
public bool Contains (T value)
View
5 mcs/class/System/Test/System.Collections.Generic/LinkedListTest.cs
@@ -84,8 +84,13 @@ public void NonCircularNodeTest ()
[Test]
public void ClearTest ()
{
+ LinkedListNode <int> node = intlist.First;
intlist.Clear ();
+
Assert.AreEqual (0, intlist.Count);
+ Assert.AreEqual (2, node.Value);
+ Assert.IsNull (node.Next);
+ Assert.IsNull (node.Previous);
}
[Test]
Something went wrong with that request. Please try again.