// This has the effect of moving the null values to the front if comparer is null
while (high > low0 && keys.GetValueImpl (high) != null)
--high;
+ while (low < high0 && keys.GetValueImpl (low) == null)
+ ++low;
} else {
while (low < high0 && cmpPivot.CompareTo (keys.GetValueImpl (low)) > 0)
++low;
var keyPivot = array [mid];
while (true) {
- // Move the walls in
- while (low < high0 && keyPivot.CompareTo (array [low]) > 0)
- ++low;
- while (high > low0 && keyPivot.CompareTo (array [high]) < 0)
- --high;
-
+ if (keyPivot == null){
+ while (low < high0 && array [low] == null)
+ ++low;
+ while (high > low0 && array [high] != null)
+ --high;
+ } else {
+ // Move the walls in
+ while (low < high0 && keyPivot.CompareTo (array [low]) > 0)
+ ++low;
+ while (high > low0 && keyPivot.CompareTo (array [high]) < 0)
+ --high;
+ }
+
if (low <= high) {
swap (array, items, low, high);
++low;
} else {
while (low < high0 && keys [low] == null)
++low;
- while (high > low0 && keys [high] == null)
+ while (high > low0 && keys [high] != null)
--high;
}
}
T keyPivot = array [mid];
while (true) {
- // Move the walls in
- while (low < high0 && comparison (array [low], keyPivot) < 0)
- ++low;
- while (high > low0 && comparison (keyPivot, array [high]) < 0)
- --high;
+ if (keyPivot == null){
+ while (low < high0 && array [low] == null)
+ ++low;
+ while (high > low0 && array [high] != null)
+ --high;
+ } else {
+ // Move the walls in
+ while (low < high0 && comparison (array [low], keyPivot) < 0)
+ ++low;
+ while (high > low0 && comparison (keyPivot, array [high]) < 0)
+ --high;
+ }
if (low <= high) {
swap<T> (array, low, high);
+2010-07-21 Miguel de Icaza <miguel@novell.com>
+
+ * Array.cs: Fixes a couple of other cases where we were missing
+ the handling for null values, fixes a broken case of null
+ handling.
+
2010-07-21 Jb Evain <jbevain@novell.com>
* AppDomain.cs: add IsFullyTrusted stub.
Assert.AreEqual (null, array.GetValue (0));
}
+ [Test]
+ public void SortNullsWithGenericVersion ()
+ {
+ string[] s1 = new string[6]{
+ "J",
+ "M",
+ null,
+ "P",
+ "T",
+ "A"};
+
+ string[] s2 = new string[]{null,
+ "A",
+ "J",
+ "M",
+ "P",
+ "T"};
+
+ Array.Sort<string> (s1);
+ for (int i = 0; i < 6; i++) {
+ Assert.AreEqual (s1[i], s2[i], "At:" + i);
+ }
+ }
+
//
// This is a test case for the case that was broken by the code contributed
// for bug #351638.
return ((string)x).CompareTo((string)y);
}
}
-
+
#if NET_4_0
[Test]
[ExpectedException (typeof (ArgumentException))]