@@ -109,8 +109,6 @@ pub struct Node {
109
109
pub children : RefCell < Vec < Handle > > ,
110
110
/// Represents this node's data.
111
111
pub data : NodeData ,
112
- /// Flag to control whether to free any children on destruction.
113
- leak_children_on_drop : Cell < bool > ,
114
112
}
115
113
116
114
impl Node {
@@ -120,36 +118,16 @@ impl Node {
120
118
data : data,
121
119
parent : Cell :: new ( None ) ,
122
120
children : RefCell :: new ( Vec :: new ( ) ) ,
123
- leak_children_on_drop : Cell :: new ( true ) ,
124
121
} )
125
122
}
126
-
127
- /// Drop any child nodes remaining in this node at destruction.
128
- ///
129
- /// RcDom's destructor automatically drops any nodes and children that are
130
- /// present in the document. This setting only affects nodes that are dropped
131
- /// by manipulating the tree before RcDom's destructor runs (such as manually
132
- /// removing children from a node after parsing is complete).
133
- ///
134
- /// Unsafety: due to the representation of children, this can trigger
135
- /// stack overflow if dropping a node with a very deep tree of children.
136
- /// This is not a recommended configuration to use when interacting with
137
- /// arbitrary HTML content.
138
- pub unsafe fn free_child_nodes_on_drop ( & self ) {
139
- self . leak_children_on_drop . set ( false ) ;
140
- }
141
123
}
142
124
143
125
impl Drop for Node {
144
126
fn drop ( & mut self ) {
145
- if !self . children . borrow ( ) . is_empty ( ) {
146
- if self . leak_children_on_drop . get ( ) {
147
- warn ! ( "Dropping node with children outside of RcDom's destructor. \
148
- Leaking memory for {} children.", self . children. borrow( ) . len( ) ) ;
149
- for child in mem:: replace ( & mut * self . children . borrow_mut ( ) , vec ! [ ] ) {
150
- mem:: forget ( child) ;
151
- }
152
- }
127
+ let mut nodes = mem:: replace ( & mut * self . children . borrow_mut ( ) , vec ! [ ] ) ;
128
+ while let Some ( node) = nodes. pop ( ) {
129
+ let children = mem:: replace ( & mut * node. children . borrow_mut ( ) , vec ! [ ] ) ;
130
+ nodes. extend ( children. into_iter ( ) ) ;
153
131
}
154
132
}
155
133
}
@@ -227,18 +205,6 @@ pub struct RcDom {
227
205
pub quirks_mode : QuirksMode ,
228
206
}
229
207
230
- impl Drop for RcDom {
231
- fn drop ( & mut self ) {
232
- // Ensure that node destructors execute linearly, rather
233
- // than recursing through a tree of arbitrary depth.
234
- let mut to_be_processed = vec ! [ self . document. clone( ) ] ;
235
- while let Some ( node) = to_be_processed. pop ( ) {
236
- to_be_processed. extend_from_slice ( & * node. children . borrow ( ) ) ;
237
- node. children . borrow_mut ( ) . clear ( ) ;
238
- }
239
- }
240
- }
241
-
242
208
impl TreeSink for RcDom {
243
209
type Output = Self ;
244
210
fn finish ( self ) -> Self {
0 commit comments