Skip to content

Commit

Permalink
perf(DeviceCollection): only check for same dataflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Belphemur committed Aug 24, 2021
1 parent c14b008 commit 00b8df9
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using NAudio.CoreAudioApi;
using SoundSwitch.Common.Framework.Audio.Device;

namespace SoundSwitch.Common.Framework.Audio.Collection
{
public class DeviceReadOnlyCollection<T> : IReadOnlyCollection<T> where T : DeviceInfo
{
private readonly DataFlow _dataFlow;
private readonly Dictionary<string, T> _byId = new();
private readonly Dictionary<string, T> _byName = new();

public DeviceReadOnlyCollection(IEnumerable<T> deviceInfos)
public DeviceReadOnlyCollection(IEnumerable<T> deviceInfos, DataFlow dataFlow)
{
_dataFlow = dataFlow;
foreach (var item in deviceInfos)
{
if (item == null)
Expand Down Expand Up @@ -42,6 +45,7 @@ IEnumerator IEnumerable.GetEnumerator()
public IEnumerable<T> IntersectWith(IEnumerable<DeviceInfo> second)
{
return second
.Where(info => info.Type == _dataFlow)
.Select(info =>
{
if (_byId.TryGetValue(info.Id, out var found))
Expand Down

0 comments on commit 00b8df9

Please sign in to comment.