aboutsummaryrefslogtreecommitdiffstats
path: root/components/selectors/parser.rs
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <emilio@crisal.io>2017-10-15 00:50:28 +0200
committerEmilio Cobos Álvarez <emilio@crisal.io>2017-10-16 08:54:00 +0200
commitf1cc225e970a882aa68fa44e67931e1f040dcc8f (patch)
treea0a5e3448bdd39760ae3d79c47c7b053ea84de06 /components/selectors/parser.rs
parent086c48210c1ea0b65c91e1b300f796758080871f (diff)
downloadservo-f1cc225e970a882aa68fa44e67931e1f040dcc8f.tar.gz
servo-f1cc225e970a882aa68fa44e67931e1f040dcc8f.zip
style: Use left-to-right indices in the invalidator.
This will make easier to create external invalidations, and also makes reasoning about the invalidator a bit easier.
Diffstat (limited to 'components/selectors/parser.rs')
-rw-r--r--components/selectors/parser.rs35
1 files changed, 21 insertions, 14 deletions
diff --git a/components/selectors/parser.rs b/components/selectors/parser.rs
index 6b87ed96720..093ccf366e1 100644
--- a/components/selectors/parser.rs
+++ b/components/selectors/parser.rs
@@ -440,12 +440,11 @@ impl<Impl: SelectorImpl> Selector<Impl> {
}
}
- /// Returns the combinator at index `index` (one-indexed from the right),
+ /// Returns the combinator at index `index` (zero-indexed from the right),
/// or panics if the component is not a combinator.
- ///
- /// FIXME(bholley): Use more intuitive indexing.
- pub fn combinator_at(&self, index: usize) -> Combinator {
- match self.0.slice[index - 1] {
+ #[inline]
+ pub fn combinator_at_match_order(&self, index: usize) -> Combinator {
+ match self.0.slice[index] {
Component::Combinator(c) => c,
ref other => {
panic!("Not a combinator: {:?}, {:?}, index: {}",
@@ -460,16 +459,24 @@ impl<Impl: SelectorImpl> Selector<Impl> {
self.0.slice.iter()
}
+ /// Returns the combinator at index `index` (zero-indexed from the left),
+ /// or panics if the component is not a combinator.
+ #[inline]
+ pub fn combinator_at_parse_order(&self, index: usize) -> Combinator {
+ match self.0.slice[self.len() - index - 1] {
+ Component::Combinator(c) => c,
+ ref other => {
+ panic!("Not a combinator: {:?}, {:?}, index: {}",
+ other, self, index)
+ }
+ }
+ }
+
/// Returns an iterator over the sequence of simple selectors and
- /// combinators, in parse order (from left to right), _starting_
- /// 'offset_from_right' entries from the past-the-end sentinel on
- /// the right. So "0" panics,. "1" iterates nothing, and "len"
- /// iterates the entire sequence.
- ///
- /// FIXME(bholley): This API is rather unintuive, and should really
- /// be changed to accept an offset from the left. Same for combinator_at.
- pub fn iter_raw_parse_order_from(&self, offset_from_right: usize) -> Rev<slice::Iter<Component<Impl>>> {
- self.0.slice[..offset_from_right].iter().rev()
+ /// combinators, in parse order (from left to right), starting from
+ /// `offset`.
+ pub fn iter_raw_parse_order_from(&self, offset: usize) -> Rev<slice::Iter<Component<Impl>>> {
+ self.0.slice[..self.len() - offset].iter().rev()
}
/// Creates a Selector from a vec of Components, specified in parse order. Used in tests.