@@ -5,7 +5,7 @@ use crate::{
5
5
} ;
6
6
use crate :: { error:: Result , treeitems_iter:: TreeItemsIterator } ;
7
7
use std:: {
8
- collections:: { BTreeMap , BTreeSet } ,
8
+ collections:: { BTreeSet , HashMap } ,
9
9
path:: Path ,
10
10
usize,
11
11
} ;
@@ -36,9 +36,12 @@ impl FileTreeItems {
36
36
fn create_items < ' a > (
37
37
list : & ' a [ & str ] ,
38
38
collapsed : & BTreeSet < & String > ,
39
- ) -> Result < ( Vec < FileTreeItem > , BTreeMap < & ' a Path , usize > ) > {
39
+ ) -> Result < ( Vec < FileTreeItem > , HashMap < & ' a Path , usize > ) > {
40
+ // scopetime::scope_time!("create_items");
41
+
40
42
let mut items = Vec :: with_capacity ( list. len ( ) ) ;
41
- let mut paths_added: BTreeMap < & Path , usize > = BTreeMap :: new ( ) ;
43
+ let mut paths_added: HashMap < & Path , usize > =
44
+ HashMap :: with_capacity ( list. len ( ) ) ;
42
45
43
46
for e in list {
44
47
{
@@ -81,7 +84,7 @@ impl FileTreeItems {
81
84
nodes : & mut Vec < FileTreeItem > ,
82
85
// helps to only add new nodes for paths that were not added before
83
86
// we also count the number of children a node has for later folding
84
- paths_added : & mut BTreeMap < & ' a Path , usize > ,
87
+ paths_added : & mut HashMap < & ' a Path , usize > ,
85
88
collapsed : & BTreeSet < & String > ,
86
89
) -> Result < ( ) > {
87
90
let mut ancestors =
@@ -91,7 +94,7 @@ impl FileTreeItems {
91
94
for c in & ancestors {
92
95
if c. parent ( ) . is_some ( ) && !paths_added. contains_key ( c) {
93
96
// add node and set count to have no children
94
- paths_added. entry ( c ) . or_insert ( 0 ) ;
97
+ paths_added. insert ( c , 0 ) ;
95
98
96
99
// increase the number of children in the parent node count
97
100
if let Some ( parent) = c. parent ( ) {
@@ -241,7 +244,7 @@ impl FileTreeItems {
241
244
242
245
fn fold_paths (
243
246
items : & mut Vec < FileTreeItem > ,
244
- paths : & BTreeMap < & Path , usize > ,
247
+ paths : & HashMap < & Path , usize > ,
245
248
) {
246
249
let mut i = 0 ;
247
250
@@ -335,7 +338,7 @@ mod tests {
335
338
#[ test]
336
339
fn test_push_path ( ) {
337
340
let mut items = Vec :: new ( ) ;
338
- let mut paths: BTreeMap < & Path , usize > = BTreeMap :: new ( ) ;
341
+ let mut paths: HashMap < & Path , usize > = HashMap :: new ( ) ;
339
342
340
343
FileTreeItems :: push_dirs (
341
344
Path :: new ( "a/b/c" ) ,
@@ -361,7 +364,7 @@ mod tests {
361
364
#[ test]
362
365
fn test_push_path2 ( ) {
363
366
let mut items = Vec :: new ( ) ;
364
- let mut paths: BTreeMap < & Path , usize > = BTreeMap :: new ( ) ;
367
+ let mut paths: HashMap < & Path , usize > = HashMap :: new ( ) ;
365
368
366
369
FileTreeItems :: push_dirs (
367
370
Path :: new ( "a/b/c" ) ,
0 commit comments