mirror of
https://github.com/extrawurst/gitui.git
synced 2024-11-22 02:12:58 +03:00
improve filetree::new performance (#760)
we used a BTreeMap where ordering does not matter and HashMap performs much better
This commit is contained in:
parent
a4817609fb
commit
0e7ac4a14c
@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## Added
|
||||
- honor `config.showUntrackedFiles` improving speed with a lot of untracked items ([#752](https://github.com/extrawurst/gitui/issues/752))
|
||||
- improve performance when opening filetree-tab ([#756](https://github.com/extrawurst/gitui/issues/756))
|
||||
|
||||
## Fixed
|
||||
- wrong file with same name shown in file tree ([#748](https://github.com/extrawurst/gitui/issues/748))
|
||||
|
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -377,6 +377,7 @@ name = "filetreelist"
|
||||
version = "0.1.1"
|
||||
dependencies = [
|
||||
"pretty_assertions",
|
||||
"scopetime",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
|
7
Makefile
7
Makefile
@ -1,11 +1,14 @@
|
||||
|
||||
.PHONY: debug build-release release-linux-musl test clippy clippy-pedantic install install-debug
|
||||
|
||||
ARGS=-l
|
||||
# ARGS=-l -d <some_path>
|
||||
|
||||
profile:
|
||||
cargo run --features=timing,pprof -- -l
|
||||
cargo run --features=timing,pprof -- ${ARGS}
|
||||
|
||||
debug:
|
||||
RUST_BACKTRACE=true cargo run --features=timing -- -l
|
||||
RUST_BACKTRACE=true cargo run --features=timing -- ${ARGS}
|
||||
|
||||
build-release:
|
||||
cargo build --release
|
||||
|
@ -12,6 +12,7 @@ categories = ["command-line-utilities"]
|
||||
keywords = ["gui","cli","terminal","ui","tui"]
|
||||
|
||||
[dependencies]
|
||||
scopetime = { path = "../scopetime", version = "0.1" }
|
||||
thiserror = "1.0"
|
||||
|
||||
[dev-dependencies]
|
||||
|
@ -5,7 +5,7 @@ use crate::{
|
||||
};
|
||||
use crate::{error::Result, treeitems_iter::TreeItemsIterator};
|
||||
use std::{
|
||||
collections::{BTreeMap, BTreeSet},
|
||||
collections::{BTreeSet, HashMap},
|
||||
path::Path,
|
||||
usize,
|
||||
};
|
||||
@ -36,9 +36,12 @@ impl FileTreeItems {
|
||||
fn create_items<'a>(
|
||||
list: &'a [&str],
|
||||
collapsed: &BTreeSet<&String>,
|
||||
) -> Result<(Vec<FileTreeItem>, BTreeMap<&'a Path, usize>)> {
|
||||
) -> Result<(Vec<FileTreeItem>, HashMap<&'a Path, usize>)> {
|
||||
// scopetime::scope_time!("create_items");
|
||||
|
||||
let mut items = Vec::with_capacity(list.len());
|
||||
let mut paths_added: BTreeMap<&Path, usize> = BTreeMap::new();
|
||||
let mut paths_added: HashMap<&Path, usize> =
|
||||
HashMap::with_capacity(list.len());
|
||||
|
||||
for e in list {
|
||||
{
|
||||
@ -81,7 +84,7 @@ impl FileTreeItems {
|
||||
nodes: &mut Vec<FileTreeItem>,
|
||||
// helps to only add new nodes for paths that were not added before
|
||||
// we also count the number of children a node has for later folding
|
||||
paths_added: &mut BTreeMap<&'a Path, usize>,
|
||||
paths_added: &mut HashMap<&'a Path, usize>,
|
||||
collapsed: &BTreeSet<&String>,
|
||||
) -> Result<()> {
|
||||
let mut ancestors =
|
||||
@ -91,7 +94,7 @@ impl FileTreeItems {
|
||||
for c in &ancestors {
|
||||
if c.parent().is_some() && !paths_added.contains_key(c) {
|
||||
// add node and set count to have no children
|
||||
paths_added.entry(c).or_insert(0);
|
||||
paths_added.insert(c, 0);
|
||||
|
||||
// increase the number of children in the parent node count
|
||||
if let Some(parent) = c.parent() {
|
||||
@ -241,7 +244,7 @@ impl FileTreeItems {
|
||||
|
||||
fn fold_paths(
|
||||
items: &mut Vec<FileTreeItem>,
|
||||
paths: &BTreeMap<&Path, usize>,
|
||||
paths: &HashMap<&Path, usize>,
|
||||
) {
|
||||
let mut i = 0;
|
||||
|
||||
@ -335,7 +338,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_push_path() {
|
||||
let mut items = Vec::new();
|
||||
let mut paths: BTreeMap<&Path, usize> = BTreeMap::new();
|
||||
let mut paths: HashMap<&Path, usize> = HashMap::new();
|
||||
|
||||
FileTreeItems::push_dirs(
|
||||
Path::new("a/b/c"),
|
||||
@ -361,7 +364,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_push_path2() {
|
||||
let mut items = Vec::new();
|
||||
let mut paths: BTreeMap<&Path, usize> = BTreeMap::new();
|
||||
let mut paths: HashMap<&Path, usize> = HashMap::new();
|
||||
|
||||
FileTreeItems::push_dirs(
|
||||
Path::new("a/b/c"),
|
||||
|
Loading…
Reference in New Issue
Block a user