Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing recursion from ComplexSelector WIP #16227

Closed
wants to merge 6 commits into from
Prev

Adding crate to cargo

Adding crate to lib

Update parser.rs

Update parser.rs

Update parser.rs

Update parser.rs

Update parser.rs

forgot to remove comment
  • Loading branch information
tictakk authored and Matthew committed Apr 7, 2017
commit d525d040d56bcaaa2b86f2dec472b34ea260a88e
@@ -20,3 +20,4 @@ bitflags = "0.7"
matches = "0.1"
cssparser = "0.12"
fnv = "1.0"
smallvec = "0.3"
@@ -6,6 +6,7 @@
#[macro_use] extern crate cssparser;
#[macro_use] extern crate matches;
extern crate fnv;
extern crate smallvec;

pub mod bloom;
pub mod matching;
@@ -1,6 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// extern crate smallvec;

This comment has been minimized.

@emilio

emilio Apr 6, 2017

Member

Please remove this.


use cssparser::{Token, Parser as CssParser, parse_nth, ToCss, serialize_identifier, CssStringWriter};
use std::ascii::AsciiExt;
@@ -376,32 +377,33 @@ impl<Impl: SelectorImpl> ToCss for Selector<Impl> {

impl<Impl: SelectorImpl> ToCss for ComplexSelector<Impl> {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
use smallvec::SmallVec;
let mut current = self;
let mut nodes = SmallVec::<[Arc<ComplexSelector<Impl>>; 8]>::new();
loop{
match current.next{
None => break,
Some((ref next, ref combinator)) => {
current = &**next;
combinator.to_css(dest)?;
nodes.push((*next).clone());
}
}
}

for simp in &self.compound_selector{
simp.to_css(dest)?;
}

for node in nodes {
for simple in &node.compound_selector {
simple.to_css(dest)?;
}
}

Ok(())
}
use smallvec::SmallVec;
let mut current = self;
let mut nodes = SmallVec::<[&Self;8]>::new();
nodes.push(current);

loop {
match current.next {
None => break,
Some((ref next, _)) => {
current = &**next;
nodes.push(next);
}
}
}

for selector in nodes.iter().rev(){
if let Some((_, ref combinator)) = selector.next{
combinator.to_css(dest)?;
}

for simple in &selector.compound_selector{
simple.to_css(dest)?;
}
}

Ok(())
}

This comment has been minimized.

@emilio

emilio Apr 6, 2017

Member

Indentation here and in the line above is off.

}

impl ToCss for Combinator {
@@ -1150,9 +1152,6 @@ fn parse_simple_pseudo_class<P, Impl>(parser: &P, name: Cow<str>) -> Result<Simp
// NB: pub module in order to access the DummyParser
#[cfg(test)]
pub mod tests {



use cssparser::{Parser as CssParser, ToCss, serialize_identifier};
use std::borrow::Cow;
use std::collections::HashMap;
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.