Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Sep 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading