Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10477


Ignore:
Timestamp:
02/20/14 14:14:55 (11 years ago)
Author:
gkronber
Message:

#2106 changed ListExtensions.StableSort to behave in the same way as ArrayExtensions.StableSort() as suggested in the review comments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Common/3.3/ListExtensions.cs

    r10324 r10477  
    3131
    3232    public static void StableSort<T>(this List<T> values, int index, int count) {
    33       var orderedList = values.Skip(index).Take(count).OrderBy(x => x).ToList();
    34       values.Clear();
    35       values.AddRange(orderedList);
     33      var orderedList = values.Skip(index).Take(count).OrderBy(x => x);
     34      int i = index;
     35      foreach (var e in orderedList)
     36        values[i++] = e;
    3637    }
    3738
     
    4142
    4243    public static void StableSort<T>(this List<T> values, int index, int count, IComparer<T> comparer) {
    43       var orderedList = values.OrderBy(x => x, comparer).ToList();
    44       values.Clear();
    45       values.AddRange(orderedList);
     44      var orderedList = values.OrderBy(x => x, comparer);
     45      int i = 0;
     46      foreach (var e in orderedList)
     47        values[i++] = e;
    4648    }
    4749
     
    5153
    5254    public static void StableSort<T>(this List<T> values, int index, int count, Comparison<T> comparison) {
    53       var orderedList = values.OrderBy(x => x, new StableSortComparer<T>(comparison)).ToList();
    54       values.Clear();
    55       values.AddRange(orderedList);
     55      var orderedList = values.OrderBy(x => x, new StableSortComparer<T>(comparison));
     56      int i = 0;
     57      foreach (var e in orderedList)
     58        values[i++] = e;
    5659    }
    5760
Note: See TracChangeset for help on using the changeset viewer.