mirror of
https://github.com/arabianq/pipewire-soundpad.git
synced 2026-04-28 06:21:23 +00:00
Optimize value lookup in GetFullStateCommand loop (#30)
Moves the check `if let Some(current_input_name) = &audio_player.input_device_name` outside the loop over `input_devices` in `GetFullStateCommand::execute`. By creating two separate loops (one for when an input device name is selected, and one for when it is not), we eliminate the overhead of evaluating the `Option` on every single iteration of the `input_devices` array. This effectively unswitches the loop and avoids repeatedly accessing the `audio_player` struct field. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
077518019f
commit
151f43f1ab
+11
-4
@@ -392,20 +392,27 @@ impl Executable for GetFullStateCommand {
|
|||||||
let mut current_input_nick = String::new();
|
let mut current_input_nick = String::new();
|
||||||
|
|
||||||
let audio_player = get_audio_player().await.lock().await;
|
let audio_player = get_audio_player().await.lock().await;
|
||||||
let current_input_name = audio_player.input_device_name.as_deref();
|
if let Some(current_input_name) = &audio_player.input_device_name {
|
||||||
for device in input_devices {
|
for device in input_devices {
|
||||||
if device.name == "pwsp-virtual-mic" {
|
if device.name == "pwsp-virtual-mic" {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(name) = current_input_name {
|
if device.name == *current_input_name {
|
||||||
if device.name == name {
|
|
||||||
current_input_nick = format!("{} - {}", device.name, device.nick);
|
current_input_nick = format!("{} - {}", device.name, device.nick);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
all_inputs.insert(device.name, device.nick);
|
all_inputs.insert(device.name, device.nick);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
for device in input_devices {
|
||||||
|
if device.name == "pwsp-virtual-mic" {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
all_inputs.insert(device.name, device.nick);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let full_state = FullState {
|
let full_state = FullState {
|
||||||
state: audio_player.get_state(),
|
state: audio_player.get_state(),
|
||||||
|
|||||||
Reference in New Issue
Block a user