Skip to content

Commit

Permalink
Improves IntersectWith code
Browse files Browse the repository at this point in the history
Take advantage of the Dictionnaries
  • Loading branch information
Antoine Aflalo committed Jun 7, 2018
1 parent 3659981 commit b22da76
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions SoundSwitch/Framework/Configuration/Device/DeviceInfoCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,21 @@ public DeviceInfoCollection(HashSet<DeviceInfo> devices)
/// <returns></returns>
public IEnumerable<MMDevice> IntersectWith(IEnumerable<MMDevice> devices)
{
var result = devices.Join(_deviceById, device => device.ID, pair => pair.Key, (device, pair) => device);
if (result.GetEnumerator().Current != null)
var devicesResult = new Dictionary<string, MMDevice>();
foreach (var mmDevice in devices)
{
return result;
if (devicesResult.ContainsKey(mmDevice.ID))
continue;

if (!_deviceById.ContainsKey(mmDevice.ID) && !_deviceByName.ContainsKey(mmDevice.FriendlyName))
continue;

devicesResult.Add(mmDevice.ID, mmDevice);

}

return devices.Join(_deviceByName, device => device.FriendlyName, pair => pair.Key, (device, pair) => device);
return devicesResult.Values;

}

public IEnumerator<DeviceInfo> GetEnumerator()
Expand Down

0 comments on commit b22da76

Please sign in to comment.