@@ -23,21 +23,20 @@ namespace Sass {
23
23
{
24
24
if (empty ()) return rhs;
25
25
Compound_Selector_Obj unified = SASS_MEMORY_COPY (rhs);
26
- for (size_t i = 0 , L = length (); i < L; ++i)
27
- {
26
+ for (const Simple_Selector_Obj& sel : elements ()) {
28
27
if (unified.isNull ()) break ;
29
- unified = at (i) ->unify_with (unified);
28
+ unified = sel ->unify_with (unified);
30
29
}
31
30
return unified.detach ();
32
31
}
33
32
34
33
Compound_Selector_Ptr Simple_Selector::unify_with (Compound_Selector_Ptr rhs)
35
34
{
36
- const size_t rsize = rhs->length ();
37
- for ( size_t i = 0 ; i < rsize; ++i)
38
- { if (* this == *rhs-> get (i)) return rhs; }
35
+ for ( const Simple_Selector_Obj& sel : rhs->elements ()) {
36
+ if (* this == *sel) return rhs;
37
+ }
39
38
const int lhs_order = this ->unification_order ();
40
- size_t i = rsize ;
39
+ size_t i = rhs-> length () ;
41
40
while (i > 0 && lhs_order < rhs->at (i - 1 )->unification_order ()) --i;
42
41
rhs->elements ().insert (rhs->elements ().begin () + i, this );
43
42
return rhs;
@@ -128,10 +127,9 @@ namespace Sass {
128
127
129
128
Compound_Selector_Ptr Id_Selector::unify_with (Compound_Selector_Ptr rhs)
130
129
{
131
- for (size_t i = 0 , L = rhs->length (); i < L; ++i)
132
- {
133
- if (Id_Selector_Ptr sel = Cast<Id_Selector>(rhs->at (i))) {
134
- if (sel->name () != name ()) return 0 ;
130
+ for (const Simple_Selector_Obj& sel : rhs->elements ()) {
131
+ if (Id_Selector_Ptr id_sel = Cast<Id_Selector>(sel)) {
132
+ if (id_sel->name () != name ()) return nullptr ;
135
133
}
136
134
}
137
135
rhs->has_line_break (has_line_break ());
@@ -140,12 +138,10 @@ namespace Sass {
140
138
141
139
Compound_Selector_Ptr Pseudo_Selector::unify_with (Compound_Selector_Ptr rhs)
142
140
{
143
- if (is_pseudo_element ())
144
- {
145
- for (size_t i = 0 , L = rhs->length (); i < L; ++i)
146
- {
147
- if (Pseudo_Selector_Ptr sel = Cast<Pseudo_Selector>(rhs->at (i))) {
148
- if (sel->is_pseudo_element () && sel->name () != name ()) return 0 ;
141
+ if (is_pseudo_element ()) {
142
+ for (const Simple_Selector_Obj& sel : rhs->elements ()) {
143
+ if (Pseudo_Selector_Ptr pseudo_sel = Cast<Pseudo_Selector>(sel)) {
144
+ if (pseudo_sel->is_pseudo_element () && pseudo_sel->name () != name ()) return nullptr ;
149
145
}
150
146
}
151
147
}
@@ -221,26 +217,22 @@ namespace Sass {
221
217
}
222
218
223
219
Selector_List_Ptr Selector_List::unify_with (Selector_List_Ptr rhs) {
224
- std::vector<Complex_Selector_Obj> unified_complex_selectors ;
220
+ std::vector<Complex_Selector_Obj> result ;
225
221
// Unify all of children with RHS's children, storing the results in `unified_complex_selectors`
226
- for (size_t lhs_i = 0 , lhs_L = length (); lhs_i < lhs_L; ++lhs_i) {
227
- Complex_Selector_Obj seq1 = (*this )[lhs_i];
228
- for (size_t rhs_i = 0 , rhs_L = rhs->length (); rhs_i < rhs_L; ++rhs_i) {
229
- Complex_Selector_Ptr seq2 = rhs->at (rhs_i);
230
-
231
- Selector_List_Obj result = seq1->unify_with (seq2);
232
- if ( result ) {
233
- for (size_t i = 0 , L = result->length (); i < L; ++i) {
234
- unified_complex_selectors.push_back ( (*result)[i] );
235
- }
222
+ for (Complex_Selector_Obj& seq1 : elements ()) {
223
+ for (Complex_Selector_Obj& seq2 : rhs->elements ()) {
224
+ Selector_List_Obj unified = seq1->unify_with (seq2);
225
+ if (unified) {
226
+ result.reserve (result.size () + unified->length ());
227
+ std::copy (unified->begin (), unified->end (), std::back_inserter (result));
236
228
}
237
229
}
238
230
}
239
231
240
232
// Creates the final Selector_List by combining all the complex selectors
241
- Selector_List_Ptr final_result = SASS_MEMORY_NEW (Selector_List, pstate ());
242
- for (auto itr = unified_complex_selectors. begin (); itr != unified_complex_selectors. end (); ++itr ) {
243
- final_result->append (*itr );
233
+ Selector_List_Ptr final_result = SASS_MEMORY_NEW (Selector_List, pstate (), result. size () );
234
+ for (Complex_Selector_Obj& sel : result ) {
235
+ final_result->append (sel );
244
236
}
245
237
return final_result;
246
238
}
0 commit comments