Skip to content

Commit

Permalink
~[] to Vec in style/selectors.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
murphm8 authored and Ms2ger committed May 4, 2014
1 parent 544bbcd commit 33d0a3a
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions src/components/style/selectors.rs
Expand Up @@ -42,7 +42,7 @@ pub enum PseudoElement {

#[deriving(Eq, Clone)]
pub struct CompoundSelector {
pub simple_selectors: ~[SimpleSelector],
pub simple_selectors: Vec<SimpleSelector>,
pub next: Option<(~CompoundSelector, Combinator)>, // c.next is left of c
}

Expand Down Expand Up @@ -71,7 +71,7 @@ pub enum SimpleSelector {
AttrSuffixMatch(AttrSelector, ~str), // [foo$=bar]

// Pseudo-classes
Negation(~[SimpleSelector]),
Negation(Vec<SimpleSelector>),
AnyLink,
Link,
Visited,
Expand Down Expand Up @@ -197,18 +197,18 @@ fn compute_specificity(mut selector: &CompoundSelector,
};
if pseudo_element.is_some() { specificity.element_selectors += 1 }

simple_selectors_specificity(selector.simple_selectors, &mut specificity);
simple_selectors_specificity(&selector.simple_selectors, &mut specificity);
loop {
match selector.next {
None => break,
Some((ref next_selector, _)) => {
selector = &**next_selector;
simple_selectors_specificity(selector.simple_selectors, &mut specificity)
simple_selectors_specificity(&selector.simple_selectors, &mut specificity)
}
}
}

fn simple_selectors_specificity(simple_selectors: &[SimpleSelector],
fn simple_selectors_specificity(simple_selectors: &Vec<SimpleSelector>,
specificity: &mut Specificity) {
for simple_selector in simple_selectors.iter() {
match simple_selector {
Expand All @@ -226,7 +226,7 @@ fn compute_specificity(mut selector: &CompoundSelector,
=> specificity.class_like_selectors += 1,
&NamespaceSelector(..) => (),
&Negation(ref negated)
=> simple_selectors_specificity(negated.as_slice(), specificity),
=> simple_selectors_specificity(negated, specificity),
}
}
}
Expand All @@ -244,11 +244,11 @@ fn compute_specificity(mut selector: &CompoundSelector,
///
/// None means invalid selector
fn parse_simple_selectors(iter: &mut Iter, namespaces: &NamespaceMap)
-> Option<(~[SimpleSelector], Option<PseudoElement>)> {
-> Option<(Vec<SimpleSelector>, Option<PseudoElement>)> {
let mut empty = true;
let mut simple_selectors = match parse_type_selector(iter, namespaces) {
InvalidTypeSelector => return None,
NotATypeSelector => ~[],
NotATypeSelector => Vec::new(),
TypeSelector(s) => { empty = false; s }
};

Expand All @@ -269,7 +269,7 @@ fn parse_simple_selectors(iter: &mut Iter, namespaces: &NamespaceMap)
enum TypeSelectorParseResult {
InvalidTypeSelector,
NotATypeSelector,
TypeSelector(~[SimpleSelector]), // Length 0 (*|*), 1 (*|E or ns|*) or 2 (|E or ns|E)
TypeSelector(Vec<SimpleSelector>), // Length 0 (*|*), 1 (*|E or ns|*) or 2 (|E or ns|E)
}

fn parse_type_selector(iter: &mut Iter, namespaces: &NamespaceMap)
Expand All @@ -279,7 +279,7 @@ fn parse_type_selector(iter: &mut Iter, namespaces: &NamespaceMap)
InvalidQualifiedName => InvalidTypeSelector,
NotAQualifiedName => NotATypeSelector,
QualifiedName(namespace, local_name) => {
let mut simple_selectors = ~[];
let mut simple_selectors = Vec::new();
match namespace {
SpecificNamespace(ns) => simple_selectors.push(NamespaceSelector(ns)),
AnyNamespace => (),
Expand Down Expand Up @@ -526,7 +526,7 @@ fn parse_pseudo_element(name: ~str) -> Option<PseudoElement> {
}


//fn parse_lang(arguments: ~[ComponentValue]) -> Option<SimpleSelector> {
//fn parse_lang(arguments: vec!(ComponentValue)) -> Option<SimpleSelector> {
// let mut iter = arguments.move_skip_whitespace();
// match iter.next() {
// Some(Ident(value)) => {
Expand All @@ -547,7 +547,7 @@ fn parse_negation(arguments: ~[ComponentValue], namespaces: &NamespaceMap)
TypeSelector(s) => s,
NotATypeSelector => {
match parse_one_simple_selector(iter, namespaces, /* inside_negation = */ true) {
SimpleSelectorResult(s) => ~[s],
SimpleSelectorResult(s) => vec!(s),
_ => return None
}
},
Expand Down Expand Up @@ -603,44 +603,44 @@ mod tests {
assert!(parse("") == None)
assert!(parse("e") == Some(vec!(Selector{
compound_selectors: Arc::new(CompoundSelector {
simple_selectors: ~[LocalNameSelector("e".to_owned())],
simple_selectors: vec!(LocalNameSelector("e".to_owned())),
next: None,
}),
pseudo_element: None,
specificity: specificity(0, 0, 1),
})))
assert!(parse(".foo") == Some(vec!(Selector{
compound_selectors: Arc::new(CompoundSelector {
simple_selectors: ~[ClassSelector("foo".to_owned())],
simple_selectors: vec!(ClassSelector("foo".to_owned())),
next: None,
}),
pseudo_element: None,
specificity: specificity(0, 1, 0),
})))
assert!(parse("#bar") == Some(vec!(Selector{
compound_selectors: Arc::new(CompoundSelector {
simple_selectors: ~[IDSelector("bar".to_owned())],
simple_selectors: vec!(IDSelector("bar".to_owned())),
next: None,
}),
pseudo_element: None,
specificity: specificity(1, 0, 0),
})))
assert!(parse("e.foo#bar") == Some(vec!(Selector{
compound_selectors: Arc::new(CompoundSelector {
simple_selectors: ~[LocalNameSelector("e".to_owned()),
ClassSelector("foo".to_owned()),
IDSelector("bar".to_owned())],
simple_selectors: vec!(LocalNameSelector("e".to_owned()),
ClassSelector("foo".to_owned()),
IDSelector("bar".to_owned())),
next: None,
}),
pseudo_element: None,
specificity: specificity(1, 1, 1),
})))
assert!(parse("e.foo #bar") == Some(vec!(Selector{
compound_selectors: Arc::new(CompoundSelector {
simple_selectors: ~[IDSelector("bar".to_owned())],
simple_selectors: vec!(IDSelector("bar".to_owned())),
next: Some((~CompoundSelector {
simple_selectors: ~[LocalNameSelector("e".to_owned()),
ClassSelector("foo".to_owned())],
simple_selectors: vec!(LocalNameSelector("e".to_owned()),
ClassSelector("foo".to_owned())),
next: None,
}, Descendant)),
}),
Expand All @@ -652,11 +652,11 @@ mod tests {
let mut namespaces = NamespaceMap::new();
assert!(parse_ns("[Foo]", &namespaces) == Some(vec!(Selector{
compound_selectors: Arc::new(CompoundSelector {
simple_selectors: ~[AttrExists(AttrSelector {
simple_selectors: vec!(AttrExists(AttrSelector {
name: "Foo".to_owned(),
lower_name: "foo".to_owned(),
namespace: SpecificNamespace(namespace::Null),
})],
})),
next: None,
}),
pseudo_element: None,
Expand All @@ -667,11 +667,11 @@ mod tests {
namespaces.default = Some(namespace::MathML);
assert!(parse_ns("[Foo]", &namespaces) == Some(vec!(Selector{
compound_selectors: Arc::new(CompoundSelector {
simple_selectors: ~[AttrExists(AttrSelector {
simple_selectors: vec!(AttrExists(AttrSelector {
name: "Foo".to_owned(),
lower_name: "foo".to_owned(),
namespace: SpecificNamespace(namespace::Null),
})],
})),
next: None,
}),
pseudo_element: None,
Expand All @@ -680,10 +680,10 @@ mod tests {
// Default namespace does apply to type selectors
assert!(parse_ns("e", &namespaces) == Some(vec!(Selector{
compound_selectors: Arc::new(CompoundSelector {
simple_selectors: ~[
simple_selectors: vec!(
NamespaceSelector(namespace::MathML),
LocalNameSelector("e".to_owned()),
],
),
next: None,
}),
pseudo_element: None,
Expand All @@ -692,17 +692,17 @@ mod tests {
// https://github.com/mozilla/servo/issues/1723
assert!(parse("::before") == Some(vec!(Selector{
compound_selectors: Arc::new(CompoundSelector {
simple_selectors: ~[],
simple_selectors: Vec::new(),
next: None,
}),
pseudo_element: Some(Before),
specificity: specificity(0, 0, 1),
})))
assert!(parse("div :after") == Some(vec!(Selector{
compound_selectors: Arc::new(CompoundSelector {
simple_selectors: ~[],
simple_selectors: Vec::new(),
next: Some((~CompoundSelector {
simple_selectors: ~[LocalNameSelector("div".to_owned())],
simple_selectors: vec!(LocalNameSelector("div".to_owned())),
next: None,
}, Descendant)),
}),
Expand Down

0 comments on commit 33d0a3a

Please sign in to comment.