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 #16347

Merged
merged 1 commit into from Apr 17, 2017
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Some generated files are not rendered by default. Learn more.

@@ -21,3 +21,4 @@ matches = "0.1"
cssparser = "0.12.1"
fnv = "1.0"
precomputed-hash = "0.1"
smallvec = "0.3"
@@ -7,6 +7,7 @@
#[macro_use] extern crate matches;
extern crate fnv;
extern crate precomputed_hash;
extern crate smallvec;

pub mod bloom;
pub mod matching;
@@ -360,12 +360,29 @@ 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 {
if let Some((ref next, ref combinator)) = self.next {
next.to_css(dest)?;
combinator.to_css(dest)?;
}
for simple in &self.compound_selector {
simple.to_css(dest)?;
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(())
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.