Skip to content

Commit

Permalink
refactor(term): count keymap capacity
Browse files Browse the repository at this point in the history
  • Loading branch information
ymgyt committed May 4, 2024
1 parent 55d3764 commit 466368f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
12 changes: 9 additions & 3 deletions crates/synd_term/src/keymap/macros.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
macro_rules! keymap {
( @count $token:tt ) => { () };

( @trie $cmd:ident ) => { $crate::keymap::KeyTrie::Command($crate::command::Command::$cmd()) };

(@trie
Expand All @@ -11,11 +13,15 @@ macro_rules! keymap {
{ $( $($key:literal)|+ => $value:tt, )+ }
) => {
{
// TODO: calcu cap
let mut map = ::std::collections::HashMap::new();
// https://danielkeep.github.io/tlborm/book/blk-counting.html#slice-length
let capacity = <[()]>::len(&[
$(
$( keymap!(@count $key) ),*
),*
]);
let mut map = ::std::collections::HashMap::with_capacity(capacity);
$(
$(
// TODO: parse KeyEvent from literal
let key_event = $crate::keymap::parse($key).unwrap();
let trie = keymap!(@trie $value );
map.insert(key_event, trie);
Expand Down
1 change: 0 additions & 1 deletion crates/synd_term/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ mod test {
#[tokio::test(flavor = "multi_thread")]
#[file_serial(a)]
async fn hello_world() -> anyhow::Result<()> {
// TODO: wrap once
tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env())
.with_line_number(true)
Expand Down

0 comments on commit 466368f

Please sign in to comment.