@@ -12,7 +12,7 @@ use astr::AStr;
1212use indextree:: { Arena , Descendants , NodeId } ;
1313use snafu:: Snafu ;
1414
15- use crate :: path;
15+ use crate :: path:: { self , VfsPath } ;
1616
1717pub mod builder;
1818
@@ -51,28 +51,32 @@ pub trait BlitFile: Clone + Sized + Debug + From<AStr> {
5151#[ derive( Debug , Clone ) ]
5252struct File < T > {
5353 id : AStr ,
54- path : AStr ,
55- file_name : Option < AStr > ,
56- parent : Option < AStr > ,
54+ path : VfsPath ,
5755 kind : Kind ,
5856 inner : T ,
5957}
6058
6159impl < T : BlitFile > File < T > {
6260 pub fn new ( inner : T ) -> Self {
63- let path = inner. path ( ) ;
64- let file_name = path:: file_name ( & path) . map ( AStr :: from) ;
65- let parent = path:: parent ( & path) . map ( AStr :: from) ;
61+ let path = VfsPath :: new ( inner. path ( ) ) ;
6662
6763 Self {
6864 id : inner. id ( ) ,
6965 path,
70- file_name,
71- parent,
7266 kind : inner. kind ( ) ,
7367 inner,
7468 }
7569 }
70+
71+ #[ inline]
72+ fn file_name ( & self ) -> & str {
73+ self . path . file_name ( )
74+ }
75+
76+ #[ inline]
77+ fn parent ( & self ) -> Option < & str > {
78+ self . path . parent ( )
79+ }
7680}
7781
7882/// Actual tree implementation, encapsulating indextree
@@ -105,7 +109,7 @@ impl<T: BlitFile> Tree<T> {
105109
106110 /// Generate a new node, store the path mapping for it
107111 fn new_node ( & mut self , data : File < T > ) -> NodeId {
108- let path = data. path . clone ( ) ;
112+ let path = data. path . astr ( ) ;
109113 let node = self . arena . new_node ( data) ;
110114 self . map . insert ( path, node) ;
111115 self . length += 1 ;
@@ -130,7 +134,7 @@ impl<T: BlitFile> Tree<T> {
130134 . children ( & self . arena )
131135 . filter_map ( |n| {
132136 let n = self . arena . get ( n) ?. get ( ) ;
133- if n. file_name == node. get ( ) . file_name {
137+ if n. file_name ( ) == node. get ( ) . file_name ( ) {
134138 Some ( n)
135139 } else {
136140 None
@@ -139,7 +143,7 @@ impl<T: BlitFile> Tree<T> {
139143 . collect :: < Vec < _ > > ( ) ;
140144 if !others. is_empty ( ) {
141145 let e = Error :: Duplicate {
142- node_path : node. get ( ) . path . clone ( ) ,
146+ node_path : node. get ( ) . path . astr ( ) ,
143147 node_id : node. get ( ) . id . clone ( ) ,
144148 other_id : others. first ( ) . unwrap ( ) . id . clone ( ) ,
145149 } ;
@@ -193,7 +197,7 @@ impl<T: BlitFile> Tree<T> {
193197 Some ( n) => * n,
194198 None => self . new_node ( orphan. clone ( ) ) ,
195199 } ;
196- if let Some ( parent) = & orphan. parent {
200+ if let Some ( parent) = orphan. parent ( ) {
197201 self . add_child_to_node ( node, parent) ?;
198202 }
199203 }
@@ -218,7 +222,7 @@ impl<T: BlitFile> Tree<T> {
218222 fn structured_children ( & self , start : & NodeId ) -> Element < ' _ , T > {
219223 let node = & self . arena [ * start] ;
220224 let item = node. get ( ) ;
221- let partial = item. file_name . as_deref ( ) . unwrap_or_default ( ) ;
225+ let partial = item. file_name ( ) ;
222226
223227 if item. kind . is_directory ( ) {
224228 let children = start
0 commit comments