Skip to content

Commit

Permalink
enhance: pack mods & key into a u32 as id instead of hashing (#104)
Browse files Browse the repository at this point in the history
* fix: Update id to be directly derived from mods + key

* Return id to 32 bit, using 16 bits for mod and 16 for key.

* cargo fmt + clippy
  • Loading branch information
mixy1 authored Sep 9, 2024
1 parent 7efa8a0 commit c9913a9
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/hotkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,11 @@ impl HotKey {
mods.insert(Modifiers::SUPER);
}

let mut hotkey = Self { mods, key, id: 0 };
hotkey.id = hotkey.generate_hash();
hotkey
}

fn generate_hash(&self) -> u32 {
let hotkey_str = self.into_string();
let mut hasher = std::collections::hash_map::DefaultHasher::new();
hotkey_str.hash(&mut hasher);
std::hash::Hasher::finish(&hasher) as u32
Self {
mods,
key,
id: mods.bits() << 16 | key as u32,
}
}

/// Returns the id associated with this hotKey
Expand Down

0 comments on commit c9913a9

Please sign in to comment.