mirror of
https://github.com/arabianq/pipewire-soundpad.git
synced 2026-04-27 22:11:22 +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
+16
-9
@@ -392,19 +392,26 @@ impl Executable for GetFullStateCommand {
|
||||
let mut current_input_nick = String::new();
|
||||
|
||||
let audio_player = get_audio_player().await.lock().await;
|
||||
let current_input_name = audio_player.input_device_name.as_deref();
|
||||
for device in input_devices {
|
||||
if device.name == "pwsp-virtual-mic" {
|
||||
continue;
|
||||
}
|
||||
if let Some(current_input_name) = &audio_player.input_device_name {
|
||||
for device in input_devices {
|
||||
if device.name == "pwsp-virtual-mic" {
|
||||
continue;
|
||||
}
|
||||
|
||||
if let Some(name) = current_input_name {
|
||||
if device.name == name {
|
||||
if device.name == *current_input_name {
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user