Skip to content

Commit

Permalink
Keymap infobox: Use Vec in place of BTree:
Browse files Browse the repository at this point in the history
BTree was being used to store a list of keyevents
for a given command. This list was only iterated
over twice to in the end be converted to a Vec.

Better to just use a Vec from start given the use-
case. Temporalily reverts helix-editor#952.
  • Loading branch information
gibbz00 committed Jan 25, 2023
1 parent 10151a9 commit 465c0ef
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions helix-term/src/keymap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use helix_view::{document::Mode, info::Info, input::KeyEvent};
use serde::Deserialize;
use std::{
borrow::Cow,
collections::{BTreeSet, HashMap},
collections::HashMap,
ops::{Deref, DerefMut},
sync::Arc,
};
Expand Down Expand Up @@ -68,7 +68,7 @@ impl KeyTrieNode {
}

pub fn infobox(&self) -> Info {
let mut body: Vec<(&str, BTreeSet<KeyEvent>)> = Vec::with_capacity(self.len());
let mut body: Vec<(&str, Vec<KeyEvent>)> = Vec::with_capacity(self.len());
for (&key, trie) in self.iter() {
let desc = match trie {
KeyTrie::Leaf(cmd) => {
Expand All @@ -82,9 +82,9 @@ impl KeyTrieNode {
};
match body.iter().position(|(d, _)| d == &desc) {
Some(pos) => {
body[pos].1.insert(key);
body[pos].1.push(key);
}
None => body.push((desc, BTreeSet::from([key]))),
None => body.push((desc, Vec::from([key]))),
}
}

Expand Down
4 changes: 2 additions & 2 deletions helix-view/src/info.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::input::KeyEvent;
use helix_core::{register::Registers, unicode::width::UnicodeWidthStr};
use std::{collections::BTreeSet, fmt::Write};
use std::fmt::Write;

#[derive(Debug)]
/// Info box used in editor. Rendering logic will be in other crate.
Expand Down Expand Up @@ -55,7 +55,7 @@ impl Info {
}
}

pub fn from_keymap(title: &str, body: Vec<(&str, BTreeSet<KeyEvent>)>) -> Self {
pub fn from_keymap(title: &str, body: Vec<(&str, Vec<KeyEvent>)>) -> Self {
let body: Vec<_> = body
.into_iter()
.map(|(desc, events)| {
Expand Down

0 comments on commit 465c0ef

Please sign in to comment.