Backport `IEnumerable<KeyValuePair<,>>.ToDictionary`

This commit is contained in:
James Groom 2023-11-18 04:26:28 +10:00 committed by GitHub
parent c2ddc40468
commit a9bfd96027
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 16 additions and 12 deletions

View File

@ -2,6 +2,7 @@
using System.Linq;
using BizHawk.Common;
using BizHawk.Common.CollectionExtensions;
namespace BizHawk.Client.Common
{
@ -43,7 +44,7 @@ namespace BizHawk.Client.Common
}
public IReadOnlyDictionary<string, int> GetPressedAxes()
=> _inputManager.ControllerInputCoalescer.AxisValues().ToDictionary(static kvp => kvp.Key, static kvp => kvp.Value);
=> _inputManager.ControllerInputCoalescer.AxisValues().ToDictionary();
public IReadOnlyList<string> GetPressedButtons()
=> _inputManager.ControllerInputCoalescer.BoolButtons().Where(static kvp => kvp.Value)

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using BizHawk.Common.CollectionExtensions;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common
@ -78,7 +79,7 @@ namespace BizHawk.Client.Common
public IReadOnlyDictionary<string, string> GetHeader()
=> _movieSession.Movie.NotActive()
? new Dictionary<string, string>()
: _movieSession.Movie.HeaderEntries.ToDictionary(static kvp => kvp.Key, static kvp => kvp.Value);
: _movieSession.Movie.HeaderEntries.ToDictionary();
public IReadOnlyList<string> GetComments()
=> _movieSession.Movie.Comments.ToList();

View File

@ -1,6 +1,9 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using BizHawk.Common.CollectionExtensions;
using Newtonsoft.Json;
namespace BizHawk.Client.Common
@ -83,8 +86,8 @@ namespace BizHawk.Client.Common
public void FromLagLog(TasLagLog log)
{
_lagLog = log._lagLog.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
_wasLag = log._wasLag.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
_lagLog = log._lagLog.ToDictionary();
_wasLag = log._wasLag.ToDictionary();
}
public void StartFromFrame(int index)

View File

@ -467,9 +467,7 @@ namespace BizHawk.Client.Common
_gapFiller.InvalidateEnd(0);
StateCache.Clear();
AddStateCache(0);
_reserved = _reserved
.Where(kvp => kvp.Key == 0)
.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
_reserved = _reserved.Where(static kvp => kvp.Key is 0).ToDictionary(); //TODO clone needed?
}
public KeyValuePair<int, Stream> GetStateClosestToFrame(int frame)
@ -526,10 +524,7 @@ namespace BizHawk.Client.Common
private bool InvalidateReserved(int frame)
{
var origCount = _reserved.Count;
_reserved = _reserved
.Where(kvp => kvp.Key <= frame)
.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
_reserved = _reserved.Where(kvp => kvp.Key <= frame).ToDictionary(); //TODO clone needed?
return _reserved.Count < origCount;
}

View File

@ -175,7 +175,7 @@ namespace BizHawk.Client.EmuHawk
{
lock (_axisValues)
{
return _axisValues.ToDictionary(d => d.Key, d => d.Value);
return _axisValues.ToDictionary();
}
}

View File

@ -283,6 +283,10 @@ namespace BizHawk.Common.CollectionExtensions
return true;
}
/// <summary>shallow clone</summary>
public static Dictionary<TKey, TValue> ToDictionary<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> list)
=> list.ToDictionary(static kvp => kvp.Key, static kvp => kvp.Value);
public static bool IsSortedAsc<T>(this IReadOnlyList<T> list)
where T : IComparable<T>
{