66use std:: collections:: BTreeMap ;
77
88use astr:: AStr ;
9+ use elsa:: FrozenVec ;
910
1011use crate :: path;
1112use crate :: tree:: { Kind , Tree } ;
@@ -51,7 +52,7 @@ impl<T: BlitFile> TreeBuilder<T> {
5152 let file = File :: new ( item) ;
5253
5354 // Find all parent paths
54- if let Some ( parent) = & file. parent {
55+ if let Some ( parent) = file. parent ( ) {
5556 let mut leading_path: Option < AStr > = None ;
5657 // Build a set of parent paths skipping `/`, yielding `usr`, `usr/bin`, etc.
5758 for component in path:: components ( parent) {
@@ -64,6 +65,7 @@ impl<T: BlitFile> TreeBuilder<T> {
6465 . insert ( full_path. clone ( ) , File :: new ( full_path. into ( ) ) ) ;
6566 }
6667 }
68+
6769 self . explicit . push ( file) ;
6870 }
6971
@@ -73,7 +75,7 @@ impl<T: BlitFile> TreeBuilder<T> {
7375
7476 // Walk again to remove accidental dupes
7577 for i in self . explicit . iter ( ) {
76- self . implicit_dirs . remove ( & i. path ) ;
78+ self . implicit_dirs . remove ( & * i. path ) ;
7779 }
7880 }
7981
@@ -85,25 +87,27 @@ impl<T: BlitFile> TreeBuilder<T> {
8587 . iter ( )
8688 . filter ( |f| matches ! ( f. kind, Kind :: Directory ) )
8789 . chain ( self . implicit_dirs . values ( ) )
88- . map ( |d| ( & d. path , d) )
90+ . map ( |d| ( & * d. path , d) )
8991 . collect :: < BTreeMap < _ , _ > > ( ) ;
9092
9193 // build a set of redirects
94+ let scratch = FrozenVec :: new ( ) ;
9295 let mut redirects = BTreeMap :: new ( ) ;
9396
9497 // Resolve symlinks-to-dirs
9598 for link in self . explicit . iter ( ) {
9699 if let Kind :: Symlink ( target) = & link. kind {
97100 // Resolve the link.
98101 let target = if target. starts_with ( '/' ) {
99- target. clone ( )
100- } else if let Some ( parent) = & link. parent {
101- path:: join ( parent, target)
102+ & * * target
103+ } else if let Some ( parent) = link. parent ( ) {
104+ scratch. push ( path:: join ( parent, target) ) ;
105+ scratch. last ( ) . unwrap ( )
102106 } else {
103- target. clone ( )
107+ & * * target
104108 } ;
105109 if all_dirs. contains_key ( & target) {
106- redirects. insert ( & link. path , target) ;
110+ redirects. insert ( & * link. path , target) ;
107111 }
108112 }
109113 }
@@ -123,14 +127,14 @@ impl<T: BlitFile> TreeBuilder<T> {
123127 // New node for this guy
124128 let node = tree. new_node ( entry. clone ( ) ) ;
125129
126- if let Some ( parent) = & entry. parent {
130+ if let Some ( parent) = entry. parent ( ) {
127131 tree. add_child_to_node ( node, parent) ?;
128132 }
129133 }
130134
131135 // Reparent any symlink redirects.
132136 for ( source_tree, target_tree) in redirects {
133- tree. reparent ( source_tree, & target_tree) ?;
137+ tree. reparent ( source_tree, target_tree) ?;
134138 }
135139 Ok ( tree)
136140 }
0 commit comments