mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-13 12:14:16 +01:00
chore: add raii, tables code from OtterGui into new Dalamud.Interface assembly
This commit is contained in:
parent
e0d4e60aad
commit
6bf1376515
22 changed files with 1356 additions and 0 deletions
29
Dalamud.Interface/StableInsertionSortExtension.cs
Normal file
29
Dalamud.Interface/StableInsertionSortExtension.cs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Dalamud.Interface;
|
||||
|
||||
internal static class StableInsertionSortExtension
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static void StableSort<T, TKey>(this IList<T> list, Func<T, TKey> selector)
|
||||
{
|
||||
var tmpList = new List<T>(list.Count);
|
||||
tmpList.AddRange(list.OrderBy(selector));
|
||||
for (var i = 0; i < tmpList.Count; ++i)
|
||||
list[i] = tmpList[i];
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static void StableSort<T>(this IList<T> list, Comparison<T> comparer)
|
||||
{
|
||||
var tmpList = new List<(T, int)>(list.Count);
|
||||
tmpList.AddRange(list.WithIndex());
|
||||
tmpList.Sort((a, b) =>
|
||||
{
|
||||
var ret = comparer(a.Item1, b.Item1);
|
||||
return ret != 0 ? ret : a.Item2.CompareTo(b.Item2);
|
||||
});
|
||||
for (var i = 0; i < tmpList.Count; ++i)
|
||||
list[i] = tmpList[i].Item1;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue