@@ -41,11 +41,11 @@ impl State {
41
41
is_host_focused : bool ,
42
42
mut changes : Option < & mut InternalChanges > ,
43
43
) {
44
- let mut orphans = HashSet :: new ( ) ;
44
+ let mut unreachable = HashSet :: new ( ) ;
45
45
46
46
if let Some ( tree) = update. tree {
47
47
if tree. root != self . data . root {
48
- orphans . insert ( self . data . root ) ;
48
+ unreachable . insert ( self . data . root ) ;
49
49
}
50
50
self . data = tree;
51
51
}
@@ -74,7 +74,7 @@ impl State {
74
74
for ( node_id, node_data) in update. nodes {
75
75
let node_data = NodeData :: from ( node_data) ;
76
76
77
- orphans . remove ( & node_id) ;
77
+ unreachable . remove ( & node_id) ;
78
78
79
79
let mut seen_child_ids = HashSet :: with_capacity ( node_data. children ( ) . len ( ) ) ;
80
80
for ( child_index, child_id) in node_data. children ( ) . iter ( ) . enumerate ( ) {
@@ -84,7 +84,7 @@ impl State {
84
84
node_id. 0 , child_id. 0
85
85
) ;
86
86
}
87
- orphans . remove ( child_id) ;
87
+ unreachable . remove ( child_id) ;
88
88
let parent_and_index = ParentAndIndex ( node_id, child_index) ;
89
89
if let Some ( child_state) = self . nodes . get_mut_cow ( child_id) {
90
90
if child_state. parent_and_index != Some ( parent_and_index) {
@@ -110,7 +110,7 @@ impl State {
110
110
}
111
111
for child_id in node_state. data . children ( ) . iter ( ) {
112
112
if !seen_child_ids. contains ( child_id) {
113
- orphans . insert ( * child_id) ;
113
+ unreachable . insert ( * child_id) ;
114
114
}
115
115
}
116
116
if * node_state. data != node_data {
@@ -144,31 +144,23 @@ impl State {
144
144
self . focus = update. focus ;
145
145
self . is_host_focused = is_host_focused;
146
146
147
- if !orphans. is_empty ( ) {
148
- let mut to_remove = Vec :: new ( ) ;
149
-
150
- fn traverse_orphan (
151
- nodes : & ChunkMap < NodeId , NodeState > ,
152
- to_remove : & mut Vec < NodeId > ,
147
+ if !unreachable. is_empty ( ) {
148
+ fn traverse_unreachable (
149
+ nodes : & mut ChunkMap < NodeId , NodeState > ,
150
+ changes : & mut Option < & mut InternalChanges > ,
153
151
id : NodeId ,
154
152
) {
155
- to_remove. push ( id) ;
156
- let node = nodes. get ( & id) . unwrap ( ) ;
153
+ if let Some ( changes) = changes {
154
+ changes. removed_node_ids . insert ( id) ;
155
+ }
156
+ let node = nodes. remove_cow ( & id) . unwrap ( ) ;
157
157
for child_id in node. data . children ( ) . iter ( ) {
158
- traverse_orphan ( nodes, to_remove , * child_id) ;
158
+ traverse_unreachable ( nodes, changes , * child_id) ;
159
159
}
160
160
}
161
161
162
- for id in orphans {
163
- traverse_orphan ( & self . nodes , & mut to_remove, id) ;
164
- }
165
-
166
- for id in to_remove {
167
- if self . nodes . remove_cow ( & id) . is_some ( ) {
168
- if let Some ( changes) = & mut changes {
169
- changes. removed_node_ids . insert ( id) ;
170
- }
171
- }
162
+ for id in unreachable {
163
+ traverse_unreachable ( & mut self . nodes , & mut changes, id) ;
172
164
}
173
165
}
174
166
0 commit comments