1919
2020use crate :: parser:: { Combinator , Component , SelectorImpl } ;
2121use crate :: sink:: Push ;
22- use servo_arc:: { Arc , HeaderWithLength , ThinArc } ;
22+ // use servo_arc::{Arc, HeaderWithLength, ThinArc};
2323use smallvec:: { self , SmallVec } ;
2424use std:: cmp;
2525use std:: iter;
@@ -36,21 +36,21 @@ use std::slice;
3636/// build(), which transforms the contents of the SelectorBuilder into a heap-
3737/// allocated Selector and leaves the builder in a drained state.
3838#[ derive( Debug ) ]
39- pub struct SelectorBuilder < Impl : SelectorImpl > {
39+ pub struct SelectorBuilder < ' i , Impl : SelectorImpl < ' i > > {
4040 /// The entire sequence of simple selectors, from left to right, without combinators.
4141 ///
4242 /// We make this large because the result of parsing a selector is fed into a new
4343 /// Arc-ed allocation, so any spilled vec would be a wasted allocation. Also,
4444 /// Components are large enough that we don't have much cache locality benefit
4545 /// from reserving stack space for fewer of them.
46- simple_selectors : SmallVec < [ Component < Impl > ; 32 ] > ,
46+ simple_selectors : SmallVec < [ Component < ' i , Impl > ; 32 ] > ,
4747 /// The combinators, and the length of the compound selector to their left.
4848 combinators : SmallVec < [ ( Combinator , usize ) ; 16 ] > ,
4949 /// The length of the current compount selector.
5050 current_len : usize ,
5151}
5252
53- impl < Impl : SelectorImpl > Default for SelectorBuilder < Impl > {
53+ impl < ' i , Impl : SelectorImpl < ' i > > Default for SelectorBuilder < ' i , Impl > {
5454 #[ inline( always) ]
5555 fn default ( ) -> Self {
5656 SelectorBuilder {
@@ -61,16 +61,16 @@ impl<Impl: SelectorImpl> Default for SelectorBuilder<Impl> {
6161 }
6262}
6363
64- impl < Impl : SelectorImpl > Push < Component < Impl > > for SelectorBuilder < Impl > {
65- fn push ( & mut self , value : Component < Impl > ) {
64+ impl < ' i , Impl : SelectorImpl < ' i > > Push < Component < ' i , Impl > > for SelectorBuilder < ' i , Impl > {
65+ fn push ( & mut self , value : Component < ' i , Impl > ) {
6666 self . push_simple_selector ( value) ;
6767 }
6868}
6969
70- impl < Impl : SelectorImpl > SelectorBuilder < Impl > {
70+ impl < ' i , Impl : SelectorImpl < ' i > > SelectorBuilder < ' i , Impl > {
7171 /// Pushes a simple selector onto the current compound selector.
7272 #[ inline( always) ]
73- pub fn push_simple_selector ( & mut self , ss : Component < Impl > ) {
73+ pub fn push_simple_selector ( & mut self , ss : Component < ' i , Impl > ) {
7474 assert ! ( !ss. is_combinator( ) ) ;
7575 self . simple_selectors . push ( ss) ;
7676 self . current_len += 1 ;
@@ -97,7 +97,7 @@ impl<Impl: SelectorImpl> SelectorBuilder<Impl> {
9797 parsed_pseudo : bool ,
9898 parsed_slotted : bool ,
9999 parsed_part : bool ,
100- ) -> ThinArc < SpecificityAndFlags , Component < Impl > > {
100+ ) -> ( SpecificityAndFlags , Vec < Component < ' i , Impl > > ) {
101101 // Compute the specificity and flags.
102102 let specificity = specificity ( self . simple_selectors . iter ( ) ) ;
103103 let mut flags = SelectorFlags :: empty ( ) ;
@@ -119,16 +119,7 @@ impl<Impl: SelectorImpl> SelectorBuilder<Impl> {
119119 pub fn build_with_specificity_and_flags (
120120 & mut self ,
121121 spec : SpecificityAndFlags ,
122- ) -> ThinArc < SpecificityAndFlags , Component < Impl > > {
123- // First, compute the total number of Components we'll need to allocate
124- // space for.
125- let full_len = self . simple_selectors . len ( ) + self . combinators . len ( ) ;
126-
127- // Create the header.
128- let header = HeaderWithLength :: new ( spec, full_len) ;
129-
130- // Create the Arc using an iterator that drains our buffers.
131-
122+ ) -> ( SpecificityAndFlags , Vec < Component < ' i , Impl > > ) {
132123 // Use a raw pointer to be able to call set_len despite "borrowing" the slice.
133124 // This is similar to SmallVec::drain, but we use a slice here because
134125 // we’re gonna traverse it non-linearly.
@@ -145,26 +136,26 @@ impl<Impl: SelectorImpl> SelectorBuilder<Impl> {
145136 combinators : self . combinators . drain ( ..) . rev ( ) ,
146137 } ;
147138
148- Arc :: into_thin ( Arc :: from_header_and_iter ( header , iter) )
139+ ( spec , iter. collect ( ) )
149140 }
150141}
151142
152- struct SelectorBuilderIter < ' a , Impl : SelectorImpl > {
153- current_simple_selectors : slice:: Iter < ' a , Component < Impl > > ,
154- rest_of_simple_selectors : & ' a [ Component < Impl > ] ,
143+ struct SelectorBuilderIter < ' a , ' i , Impl : SelectorImpl < ' i > > {
144+ current_simple_selectors : slice:: Iter < ' a , Component < ' i , Impl > > ,
145+ rest_of_simple_selectors : & ' a [ Component < ' i , Impl > ] ,
155146 combinators : iter:: Rev < smallvec:: Drain < ' a , [ ( Combinator , usize ) ; 16 ] > > ,
156147}
157148
158- impl < ' a , Impl : SelectorImpl > ExactSizeIterator for SelectorBuilderIter < ' a , Impl > {
149+ impl < ' a , ' i , Impl : SelectorImpl < ' i > > ExactSizeIterator for SelectorBuilderIter < ' a , ' i , Impl > {
159150 fn len ( & self ) -> usize {
160151 self . current_simple_selectors . len ( ) +
161152 self . rest_of_simple_selectors . len ( ) +
162153 self . combinators . len ( )
163154 }
164155}
165156
166- impl < ' a , Impl : SelectorImpl > Iterator for SelectorBuilderIter < ' a , Impl > {
167- type Item = Component < Impl > ;
157+ impl < ' a , ' i , Impl : SelectorImpl < ' i > > Iterator for SelectorBuilderIter < ' a , ' i , Impl > {
158+ type Item = Component < ' i , Impl > ;
168159 #[ inline( always) ]
169160 fn next ( & mut self ) -> Option < Self :: Item > {
170161 if let Some ( simple_selector_ref) = self . current_simple_selectors . next ( ) {
@@ -262,22 +253,22 @@ impl From<Specificity> for u32 {
262253 }
263254}
264255
265- fn specificity < Impl > ( iter : slice:: Iter < Component < Impl > > ) -> u32
256+ fn specificity < ' i , Impl > ( iter : slice:: Iter < Component < ' i , Impl > > ) -> u32
266257where
267- Impl : SelectorImpl ,
258+ Impl : SelectorImpl < ' i > ,
268259{
269260 complex_selector_specificity ( iter) . into ( )
270261}
271262
272- fn complex_selector_specificity < Impl > ( iter : slice:: Iter < Component < Impl > > ) -> Specificity
263+ fn complex_selector_specificity < ' i , Impl > ( iter : slice:: Iter < Component < ' i , Impl > > ) -> Specificity
273264where
274- Impl : SelectorImpl ,
265+ Impl : SelectorImpl < ' i > ,
275266{
276- fn simple_selector_specificity < Impl > (
277- simple_selector : & Component < Impl > ,
267+ fn simple_selector_specificity < ' i , Impl > (
268+ simple_selector : & Component < ' i , Impl > ,
278269 specificity : & mut Specificity ,
279270 ) where
280- Impl : SelectorImpl ,
271+ Impl : SelectorImpl < ' i > ,
281272 {
282273 match * simple_selector {
283274 Component :: Combinator ( ..) => {
0 commit comments