mirror of
https://github.com/extrawurst/gitui.git
synced 2024-11-22 11:03:25 +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
|
## Added
|
||||||
- honor `config.showUntrackedFiles` improving speed with a lot of untracked items ([#752](https://github.com/extrawurst/gitui/issues/752))
|
- 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
|
## Fixed
|
||||||
- wrong file with same name shown in file tree ([#748](https://github.com/extrawurst/gitui/issues/748))
|
- 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"
|
version = "0.1.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"pretty_assertions",
|
"pretty_assertions",
|
||||||
|
"scopetime",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
7
Makefile
7
Makefile
@ -1,11 +1,14 @@
|
|||||||
|
|
||||||
.PHONY: debug build-release release-linux-musl test clippy clippy-pedantic install install-debug
|
.PHONY: debug build-release release-linux-musl test clippy clippy-pedantic install install-debug
|
||||||
|
|
||||||
|
ARGS=-l
|
||||||
|
# ARGS=-l -d <some_path>
|
||||||
|
|
||||||
profile:
|
profile:
|
||||||
cargo run --features=timing,pprof -- -l
|
cargo run --features=timing,pprof -- ${ARGS}
|
||||||
|
|
||||||
debug:
|
debug:
|
||||||
RUST_BACKTRACE=true cargo run --features=timing -- -l
|
RUST_BACKTRACE=true cargo run --features=timing -- ${ARGS}
|
||||||
|
|
||||||
build-release:
|
build-release:
|
||||||
cargo build --release
|
cargo build --release
|
||||||
|
@ -12,6 +12,7 @@ categories = ["command-line-utilities"]
|
|||||||
keywords = ["gui","cli","terminal","ui","tui"]
|
keywords = ["gui","cli","terminal","ui","tui"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
scopetime = { path = "../scopetime", version = "0.1" }
|
||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
@ -5,7 +5,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use crate::{error::Result, treeitems_iter::TreeItemsIterator};
|
use crate::{error::Result, treeitems_iter::TreeItemsIterator};
|
||||||
use std::{
|
use std::{
|
||||||
collections::{BTreeMap, BTreeSet},
|
collections::{BTreeSet, HashMap},
|
||||||
path::Path,
|
path::Path,
|
||||||
usize,
|
usize,
|
||||||
};
|
};
|
||||||
@ -36,9 +36,12 @@ impl FileTreeItems {
|
|||||||
fn create_items<'a>(
|
fn create_items<'a>(
|
||||||
list: &'a [&str],
|
list: &'a [&str],
|
||||||
collapsed: &BTreeSet<&String>,
|
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 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 {
|
for e in list {
|
||||||
{
|
{
|
||||||
@ -81,7 +84,7 @@ impl FileTreeItems {
|
|||||||
nodes: &mut Vec<FileTreeItem>,
|
nodes: &mut Vec<FileTreeItem>,
|
||||||
// helps to only add new nodes for paths that were not added before
|
// 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
|
// 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>,
|
collapsed: &BTreeSet<&String>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let mut ancestors =
|
let mut ancestors =
|
||||||
@ -91,7 +94,7 @@ impl FileTreeItems {
|
|||||||
for c in &ancestors {
|
for c in &ancestors {
|
||||||
if c.parent().is_some() && !paths_added.contains_key(c) {
|
if c.parent().is_some() && !paths_added.contains_key(c) {
|
||||||
// add node and set count to have no children
|
// 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
|
// increase the number of children in the parent node count
|
||||||
if let Some(parent) = c.parent() {
|
if let Some(parent) = c.parent() {
|
||||||
@ -241,7 +244,7 @@ impl FileTreeItems {
|
|||||||
|
|
||||||
fn fold_paths(
|
fn fold_paths(
|
||||||
items: &mut Vec<FileTreeItem>,
|
items: &mut Vec<FileTreeItem>,
|
||||||
paths: &BTreeMap<&Path, usize>,
|
paths: &HashMap<&Path, usize>,
|
||||||
) {
|
) {
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
|
|
||||||
@ -335,7 +338,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_push_path() {
|
fn test_push_path() {
|
||||||
let mut items = Vec::new();
|
let mut items = Vec::new();
|
||||||
let mut paths: BTreeMap<&Path, usize> = BTreeMap::new();
|
let mut paths: HashMap<&Path, usize> = HashMap::new();
|
||||||
|
|
||||||
FileTreeItems::push_dirs(
|
FileTreeItems::push_dirs(
|
||||||
Path::new("a/b/c"),
|
Path::new("a/b/c"),
|
||||||
@ -361,7 +364,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_push_path2() {
|
fn test_push_path2() {
|
||||||
let mut items = Vec::new();
|
let mut items = Vec::new();
|
||||||
let mut paths: BTreeMap<&Path, usize> = BTreeMap::new();
|
let mut paths: HashMap<&Path, usize> = HashMap::new();
|
||||||
|
|
||||||
FileTreeItems::push_dirs(
|
FileTreeItems::push_dirs(
|
||||||
Path::new("a/b/c"),
|
Path::new("a/b/c"),
|
||||||
|
Loading…
Reference in New Issue
Block a user