enhance: pack mods & key into a u32 as id instead of hashing (#104)

* 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
This commit is contained in:
mixy1
2024-09-10 01:17:14 +02:00
committed by GitHub
parent 7efa8a055d
commit c9913a9766

View File

@@ -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