diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2017-10-16 03:41:54 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-16 03:41:54 -0500 |
commit | a759ded65d965b54c535c74d460f60a782e51487 (patch) | |
tree | d547715521018cc6e40613d9711c492f4aa5c47a /components/selectors/parser.rs | |
parent | 9b82d08dc5ca002b34662f8058330e069d1aca15 (diff) | |
parent | f1cc225e970a882aa68fa44e67931e1f040dcc8f (diff) | |
download | servo-a759ded65d965b54c535c74d460f60a782e51487.tar.gz servo-a759ded65d965b54c535c74d460f60a782e51487.zip |
Auto merge of #18884 - emilio:invalidator-ltr, r=heycam
style: Use left-to-right indices in the invalidator.
This will make easier to create external invalidations that don't point to a combinator,
and also makes reasoning about the invalidator a bit easier.
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18884)
<!-- Reviewable:end -->
Diffstat (limited to 'components/selectors/parser.rs')
-rw-r--r-- | components/selectors/parser.rs | 35 |
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. |