Skip to content

fix: Replaced match with HashMap for faster evdevmapping#5

Merged
lavafroth merged 4 commits intowaycrate:masterfrom
nots1dd:master
Mar 23, 2025
Merged

fix: Replaced match with HashMap for faster evdevmapping#5
lavafroth merged 4 commits intowaycrate:masterfrom
nots1dd:master

Conversation

@nots1dd
Copy link
Copy Markdown
Contributor

@nots1dd nots1dd commented Mar 22, 2025

Solves #4

Added lazy_static to Cargo.toml

  1. Optimized evdev mapping insertion times with HashMap
  2. Loaded the mapping lazily

Tested the above changes with:

cargo test

Added lazy_static to Cargo.toml

1. Optimized evdev mapping insertion times with HashMap
2. Loaded the mapping lazily
@lavafroth
Copy link
Copy Markdown
Collaborator

lavafroth commented Mar 22, 2025 via email

@nots1dd
Copy link
Copy Markdown
Contributor Author

nots1dd commented Mar 22, 2025

Hi, could we use phf for this? It would build the lookup table at compile time, which is especially useful for us since we already know all the keys in the map. Perhaps check out https://docs.rs/phf

Ah yes that makes sense, I'll take a look at it and modify the PR then

Removed lazy_static from Cargo.toml.
Added phf and phf macros to Cargo.toml

1. Replaced `HashMap` with `phf::Map` for loading the static evdev
mapping at compile time
@nots1dd
Copy link
Copy Markdown
Contributor Author

nots1dd commented Mar 22, 2025

Hi, could we use phf for this? It would build the lookup table at compile time, which is especially useful for us since we already know all the keys in the map. Perhaps check out https://docs.rs/phf

I have made the requested changes, the API was quite simple to work with. Also I didnt add function keys till 24 (so f1-f12) since the test was passing without them, is this fine?

@nots1dd
Copy link
Copy Markdown
Contributor Author

nots1dd commented Mar 22, 2025

Hi, could we use phf for this? It would build the lookup table at compile time, which is especially useful for us since we already know all the keys in the map. Perhaps check out https://docs.rs/phf

I have made the requested changes, the API was quite simple to work with. Also I didnt add function keys till 24 (so f1-f12) since the test was passing without them, is this fine?

Never mind, I still have added all the previous keymaps that existed to not cause any trouble in the future.

@lavafroth lavafroth merged commit f6f708c into waycrate:master Mar 23, 2025
1 check passed
@lavafroth
Copy link
Copy Markdown
Collaborator

Thank you for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants