changed 2 functions to be slightly more efficient (u8 instead of i32)

This commit is contained in:
Djairo Hougee 2023-05-12 14:31:06 +02:00
parent 69bfa65d13
commit dd7da4533b
2 changed files with 2 additions and 6 deletions

View File

@ -158,11 +158,7 @@ impl Config {
/// If the given identity is not in the map, the value of i32::MAX is returned instead. /// If the given identity is not in the map, the value of i32::MAX is returned instead.
/// ///
/// TODO: using a HashMap would be more efficient i think. /// TODO: using a HashMap would be more efficient i think.
pub fn find_player_priorities_idx(&self, name: &str) -> i32 { pub fn find_player_priorities_idx(&self, name: &str) -> u8 {
match self.player_priorities.iter()
.position(|x| x.eq(&name)) {
Some(idx) => idx as i32,
None => i32::MAX,
} }
} }

View File

@ -38,7 +38,7 @@ pub fn update_players(pf: &PlayerFinder, cfg: &Config, mut data: &mut Data) {
if players.is_empty() { if players.is_empty() {
data.current_player = None; data.current_player = None;
} else { } else {
let mut active: BTreeMap<i32, Player> = BTreeMap::new(); let mut active: BTreeMap<u8, Player> = BTreeMap::new();
for player in players { for player in players {
if let Ok(mpris::PlaybackStatus::Playing) = player.get_playback_status() { if let Ok(mpris::PlaybackStatus::Playing) = player.get_playback_status() {
let idx = cfg.find_player_priorities_idx(player.identity()); let idx = cfg.find_player_priorities_idx(player.identity());