File tree Expand file tree Collapse file tree 2 files changed +24
-7
lines changed
Expand file tree Collapse file tree 2 files changed +24
-7
lines changed Original file line number Diff line number Diff line change @@ -138,11 +138,20 @@ impl Fdt {
138138 . unwrap_or_else ( || path. to_string ( ) ) ;
139139
140140 NodeIter :: new ( self . root ( ) ) . filter_map ( move |node_ref| {
141- if node_ref. ctx . current_path == path {
142- Some ( node_ref)
143- } else {
144- None
141+ let want = path. split ( "/" ) ;
142+ let got = node_ref. ctx . current_path . split ( "/" ) ;
143+ let last_idx = core:: cmp:: min ( want. clone ( ) . count ( ) , got. clone ( ) . count ( ) ) ;
144+ for ( w, g) in want. zip ( got) . take ( last_idx - 1 ) {
145+ if w != g {
146+ return None ;
147+ }
148+ }
149+ let want_name = path. rsplit ( '/' ) . next ( ) . unwrap_or ( "" ) ;
150+ let got_name = node_ref. node . name ( ) ;
151+ if !got_name. starts_with ( want_name) {
152+ return None ;
145153 }
154+ Some ( node_ref)
146155 } )
147156 }
148157
Original file line number Diff line number Diff line change 11use core:: {
22 fmt:: Debug ,
3- ops:: { Deref , DerefMut } ,
3+ ops:: { Deref , DerefMut } , slice :: IterMut ,
44} ;
55
66use alloc:: vec:: Vec ;
@@ -63,6 +63,12 @@ pub enum NodeMut<'a> {
6363 Gerneric ( NodeMutGen < ' a > ) ,
6464}
6565
66+ impl < ' a > NodeMut < ' a > {
67+ pub fn new ( node : & ' a mut Node , ctx : Context < ' a > ) -> Self {
68+ Self :: Gerneric ( NodeMutGen { node, ctx } )
69+ }
70+ }
71+
6672impl < ' a > Deref for NodeMut < ' a > {
6773 type Target = NodeMutGen < ' a > ;
6874
@@ -111,13 +117,15 @@ impl<'a> Iterator for NodeIter<'a> {
111117}
112118
113119pub struct NodeIterMut < ' a > {
114- stack : Vec < ( & ' a mut Node , Context < ' a > ) > ,
120+ ctx : Context < ' a > ,
121+ iter : IterMut < ' a , Node > ,
115122}
116123
117124impl < ' a > NodeIterMut < ' a > {
118125 pub fn new ( root : & ' a mut Node ) -> Self {
119126 Self {
120- stack : vec ! [ ( root, Context :: new( ) ) ] ,
127+ ctx : Context :: new ( ) ,
128+ iter : root. children . iter_mut ( ) ,
121129 }
122130 }
123131}
You can’t perform that action at this time.
0 commit comments