Skip to content

Commit 64d5dd6

Browse files
committed
perf(device::cache): use array under the hood instead of the whole DeviceReadOnlyCollection
1 parent a113175 commit 64d5dd6

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

SoundSwitch/Framework/Audio/Lister/CachedAudioDeviceLister.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ namespace SoundSwitch.Framework.Audio.Lister
3232
public class CachedAudioDeviceLister : IAudioDeviceLister
3333
{
3434
/// <inheritdoc />
35-
private DeviceReadOnlyCollection<DeviceFullInfo> PlaybackDevices { get; set; } = new(Enumerable.Empty<DeviceFullInfo>(), DataFlow.Render);
35+
private DeviceFullInfo[] PlaybackDevices { get; set; } = Array.Empty<DeviceFullInfo>();
3636

3737
/// <inheritdoc />
38-
private DeviceReadOnlyCollection<DeviceFullInfo> RecordingDevices { get; set; } = new(Enumerable.Empty<DeviceFullInfo>(), DataFlow.Capture);
38+
private DeviceFullInfo[] RecordingDevices { get; set; } = Array.Empty<DeviceFullInfo>();
3939

4040
/// <summary>
4141
/// Get devices per type and state
@@ -150,8 +150,8 @@ public void Refresh(CancellationToken cancellationToken = default)
150150
device.Dispose();
151151
}
152152

153-
PlaybackDevices = new DeviceReadOnlyCollection<DeviceFullInfo>(playbackDevices.Values, DataFlow.Render);
154-
RecordingDevices = new DeviceReadOnlyCollection<DeviceFullInfo>(recordingDevices.Values, DataFlow.Capture);
153+
PlaybackDevices = playbackDevices.Values.ToArray();
154+
RecordingDevices = recordingDevices.Values.ToArray();
155155

156156

157157
_context.Information("Refreshed all devices in {@StopTime}. {@Recording}/rec, {@Playback}/play", stopWatch.Elapsed, recordingDevices.Count, playbackDevices.Count);

0 commit comments

Comments
 (0)