Skip to content

Commit 4989cda

Browse files
committed
fix: State::from_tree() is now faster.
It uses depth-first traversal out of the box which allows it to save the sorting in the end. It's also a little bit faster.
1 parent 433b409 commit 4989cda

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

gix-index/src/init.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ pub mod from_tree {
33
use std::collections::VecDeque;
44

55
use bstr::{BStr, BString, ByteSlice, ByteVec};
6-
use gix_object::{tree, tree::EntryKind, FindExt};
7-
use gix_traverse::tree::{breadthfirst, visit::Action, Visit};
6+
use gix_object::{tree, tree::EntryKind};
7+
use gix_traverse::tree::{depthfirst, visit::Action, Visit};
88

99
use crate::{
1010
entry::{Flags, Mode, Stat},
@@ -21,7 +21,7 @@ pub mod from_tree {
2121
source: gix_validate::path::component::Error,
2222
},
2323
#[error(transparent)]
24-
Traversal(#[from] gix_traverse::tree::breadthfirst::Error),
24+
Traversal(#[from] gix_traverse::tree::depthfirst::Error),
2525
}
2626

2727
/// Initialization
@@ -58,12 +58,8 @@ pub mod from_tree {
5858
Find: gix_object::Find,
5959
{
6060
let _span = gix_features::trace::coarse!("gix_index::State::from_tree()");
61-
let mut buf = Vec::new();
62-
let root = objects
63-
.find_tree_iter(tree, &mut buf)
64-
.map_err(breadthfirst::Error::from)?;
6561
let mut delegate = CollectEntries::new(validate);
66-
match breadthfirst(root, breadthfirst::State::default(), &objects, &mut delegate) {
62+
match depthfirst(tree.to_owned(), depthfirst::State::default(), &objects, &mut delegate) {
6763
Ok(()) => {}
6864
Err(gix_traverse::tree::breadthfirst::Error::Cancelled) => {
6965
let (path, err) = delegate
@@ -76,15 +72,17 @@ pub mod from_tree {
7672
}
7773

7874
let CollectEntries {
79-
mut entries,
75+
entries,
8076
path_backing,
8177
path: _,
8278
path_deque: _,
8379
validate: _,
84-
invalid_path: _,
80+
invalid_path,
8581
} = delegate;
8682

87-
entries.sort_by(|a, b| Entry::cmp_filepaths(a.path_in(&path_backing), b.path_in(&path_backing)));
83+
if let Some((path, err)) = invalid_path {
84+
return Err(Error::InvalidComponent { path, source: err });
85+
}
8886

8987
Ok(State {
9088
object_hash: tree.kind(),

0 commit comments

Comments
 (0)