@@ -5,8 +5,6 @@ use crate::rewritable_units::{DocumentEnd, Token, TokenCaptureFlags};
5
5
use crate :: selectors_vm:: { AuxStartTagInfoRequest , ElementData , SelectorMatchingVm , VmError } ;
6
6
use crate :: transform_stream:: * ;
7
7
use hashbrown:: HashSet ;
8
- use std:: cell:: RefCell ;
9
- use std:: rc:: Rc ;
10
8
11
9
#[ derive( Default ) ]
12
10
pub struct ElementDescriptor {
@@ -25,7 +23,7 @@ impl ElementData for ElementDescriptor {
25
23
}
26
24
27
25
pub struct HtmlRewriteController < ' h > {
28
- handlers_dispatcher : Rc < RefCell < ContentHandlersDispatcher < ' h > > > ,
26
+ handlers_dispatcher : ContentHandlersDispatcher < ' h > ,
29
27
selector_matching_vm : Option < SelectorMatchingVm < ElementDescriptor > > ,
30
28
}
31
29
@@ -36,32 +34,22 @@ impl<'h> HtmlRewriteController<'h> {
36
34
selector_matching_vm : Option < SelectorMatchingVm < ElementDescriptor > > ,
37
35
) -> Self {
38
36
HtmlRewriteController {
39
- handlers_dispatcher : Rc :: new ( RefCell :: new ( handlers_dispatcher ) ) ,
37
+ handlers_dispatcher,
40
38
selector_matching_vm,
41
39
}
42
40
}
43
41
}
44
42
45
- // NOTE: it's a macro instead of an instance method, so it can be executed
46
- // when we hold a mutable reference for the selector matching VM.
47
- macro_rules! create_match_handler {
48
- ( $self: tt) => { {
49
- let handlers_dispatcher = Rc :: clone( & $self. handlers_dispatcher) ;
50
-
51
- move |m| handlers_dispatcher. borrow_mut( ) . start_matching( m)
52
- } } ;
53
- }
54
-
55
43
impl < ' h > HtmlRewriteController < ' h > {
56
44
#[ inline]
57
45
fn respond_to_aux_info_request (
58
46
aux_info_req : AuxStartTagInfoRequest < ElementDescriptor , SelectorHandlersLocator > ,
59
47
) -> StartTagHandlingResult < Self > {
60
48
Err ( DispatcherError :: InfoRequest ( Box :: new (
61
49
move |this, aux_info| {
62
- let mut match_handler = create_match_handler ! ( this) ;
63
-
64
50
if let Some ( ref mut vm) = this. selector_matching_vm {
51
+ let mut match_handler = |m| this. handlers_dispatcher . start_matching ( m) ;
52
+
65
53
aux_info_req ( vm, aux_info, & mut match_handler)
66
54
. map_err ( RewritingError :: MemoryLimitExceeded ) ?;
67
55
}
@@ -73,7 +61,7 @@ impl<'h> HtmlRewriteController<'h> {
73
61
74
62
#[ inline]
75
63
fn get_capture_flags ( & self ) -> TokenCaptureFlags {
76
- self . handlers_dispatcher . borrow ( ) . get_token_capture_flags ( )
64
+ self . handlers_dispatcher . get_token_capture_flags ( )
77
65
}
78
66
}
79
67
@@ -90,7 +78,7 @@ impl TransformController for HtmlRewriteController<'_> {
90
78
) -> StartTagHandlingResult < Self > {
91
79
match self . selector_matching_vm {
92
80
Some ( ref mut vm) => {
93
- let mut match_handler = create_match_handler ! ( self ) ;
81
+ let mut match_handler = |m| self . handlers_dispatcher . start_matching ( m ) ;
94
82
95
83
match vm. exec_for_start_tag ( local_name, ns, & mut match_handler) {
96
84
Ok ( _) => Ok ( self . get_capture_flags ( ) ) ,
@@ -108,10 +96,8 @@ impl TransformController for HtmlRewriteController<'_> {
108
96
109
97
fn handle_end_tag ( & mut self , local_name : LocalName ) -> TokenCaptureFlags {
110
98
if let Some ( ref mut vm) = self . selector_matching_vm {
111
- let handlers_dispatcher = Rc :: clone ( & self . handlers_dispatcher ) ;
112
-
113
- vm. exec_for_end_tag ( local_name, move |elem_desc| {
114
- handlers_dispatcher. borrow_mut ( ) . stop_matching ( elem_desc) ;
99
+ vm. exec_for_end_tag ( local_name, |elem_desc| {
100
+ self . handlers_dispatcher . stop_matching ( elem_desc) ;
115
101
} ) ;
116
102
}
117
103
@@ -126,14 +112,12 @@ impl TransformController for HtmlRewriteController<'_> {
126
112
. and_then ( SelectorMatchingVm :: current_element_data_mut) ;
127
113
128
114
self . handlers_dispatcher
129
- . borrow_mut ( )
130
115
. handle_token ( token, current_element_data)
131
116
. map_err ( RewritingError :: ContentHandlerError )
132
117
}
133
118
134
119
fn handle_end ( & mut self , document_end : & mut DocumentEnd ) -> Result < ( ) , RewritingError > {
135
120
self . handlers_dispatcher
136
- . borrow_mut ( )
137
121
. handle_end ( document_end)
138
122
. map_err ( RewritingError :: ContentHandlerError )
139
123
}
@@ -142,7 +126,6 @@ impl TransformController for HtmlRewriteController<'_> {
142
126
fn should_emit_content ( & self ) -> bool {
143
127
!self
144
128
. handlers_dispatcher
145
- . borrow ( )
146
129
. has_matched_elements_with_removed_content ( )
147
130
}
148
131
}
0 commit comments