Skip to content

Commit

Permalink
maintain sorting even though we have a map - each render must allocat…
Browse files Browse the repository at this point in the history
…e now

Maybe it's better to just spend the time searching through an array,
which we could sort before and do a bisection.

... sounds better actually.

Even though... that might even be more expensive if the sorting is
done every time. Just stick to a list, huh?
  • Loading branch information
Sebastian Thiel committed Jun 6, 2019
1 parent 5cff69c commit 8d21dbb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/interactive/app/eventloop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub type EntryMarkMap = BTreeMap<TreeIndex, EntryMark>;
pub struct EntryMark {
pub size: u64,
pub path: PathBuf,
pub index: usize,
}

#[derive(Default)]
Expand Down
13 changes: 11 additions & 2 deletions src/interactive/widgets/mark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,19 @@ impl MarkPane {
self.marked.remove(&index);
} else {
if let Some(e) = tree.node_weight(index) {
let sorting_index = self
.marked
.values()
.map(|v| v.index)
.max()
.unwrap_or(0)
.wrapping_add(1);
self.marked.insert(
index,
EntryMark {
size: e.size,
path: path_of(tree, index),
index: sorting_index,
},
);
}
Expand Down Expand Up @@ -85,8 +93,9 @@ impl MarkPane {
let MarkPaneProps { border_style } = props.borrow();

let marked: &_ = &self.marked;
let title = format!("Marked Entries: {}", marked.len());
let block = Block::default()
.title("Marked Entries")
.title(&title)
.border_style(*border_style)
.borders(Borders::ALL);
let entry_in_view = self
Expand All @@ -96,7 +105,7 @@ impl MarkPane {
let selected = self.selected;
let entries = marked
.values()
.sorted_by_key(|v| &v.path)
.sorted_by_key(|v| &v.index)
.enumerate()
.map(|(idx, v)| {
let modifier = match selected {
Expand Down

0 comments on commit 8d21dbb

Please sign in to comment.