test: Optimize StubAutofacIndex.AddRange()

pull/314/head
Robert Dailey 6 months ago
parent e90443c58b
commit 33e59ca98e

@ -3,10 +3,11 @@ using Autofac.Features.Indexed;
namespace Recyclarr.TestLibrary.Autofac; namespace Recyclarr.TestLibrary.Autofac;
[UsedImplicitly]
public class StubAutofacIndex<TKey, TValue> : IIndex<TKey, TValue> public class StubAutofacIndex<TKey, TValue> : IIndex<TKey, TValue>
where TKey : notnull where TKey : notnull
{ {
private Dictionary<TKey, TValue> _values = new(); private readonly Dictionary<TKey, TValue> _values = new();
public StubAutofacIndex() public StubAutofacIndex()
{ {
@ -24,7 +25,10 @@ public class StubAutofacIndex<TKey, TValue> : IIndex<TKey, TValue>
public void AddRange(IEnumerable<(TKey, TValue)> pairs) public void AddRange(IEnumerable<(TKey, TValue)> pairs)
{ {
_values = _values.Union(pairs.ToDictionary(x => x.Item1, x => x.Item2)).ToDictionary(); foreach (var (key, value) in pairs)
{
_values[key] = value;
}
} }
public bool TryGetValue(TKey key, [UnscopedRef] out TValue value) public bool TryGetValue(TKey key, [UnscopedRef] out TValue value)

Loading…
Cancel
Save