use back() rather than indexing at len - 1

This commit is contained in:
Connor Skees 2020-08-05 03:22:54 -04:00
parent 61ef52eb3f
commit 8fabda6363
2 changed files with 7 additions and 23 deletions

View File

@ -594,7 +594,7 @@ impl<'a> Parser<'a> {
self.toks.next(); self.toks.next();
self.whitespace_or_comment(); self.whitespace_or_comment();
if let Some(Token { kind: ']', pos }) = self.toks.peek() { if let Some(Token { kind: ']', pos }) = self.toks.peek() {
span = span.merge(*pos); span = span.merge(*pos);
self.toks.next(); self.toks.next();
IntermediateValue::Value(HigherIntermediateValue::Literal(Value::List( IntermediateValue::Value(HigherIntermediateValue::Literal(Value::List(

View File

@ -346,16 +346,8 @@ fn merge_final_combinators(
) -> Option<Vec<Vec<Vec<ComplexSelectorComponent>>>> { ) -> Option<Vec<Vec<Vec<ComplexSelectorComponent>>>> {
let mut result = result.unwrap_or_default(); let mut result = result.unwrap_or_default();
if (components_one.is_empty() if (components_one.is_empty() || !components_one.back().unwrap().is_combinator())
|| !components_one && (components_two.is_empty() || !components_two.back().unwrap().is_combinator())
.get(components_one.len() - 1)
.unwrap()
.is_combinator())
&& (components_two.is_empty()
|| !components_two
.get(components_two.len() - 1)
.unwrap()
.is_combinator())
{ {
return Some(Vec::from(result)); return Some(Vec::from(result));
} }
@ -539,12 +531,8 @@ fn merge_final_combinators(
} }
(Some(combinator_one), None) => { (Some(combinator_one), None) => {
if *combinator_one == Combinator::Child && !components_two.is_empty() { if *combinator_one == Combinator::Child && !components_two.is_empty() {
if let Some(ComplexSelectorComponent::Compound(c1)) = if let Some(ComplexSelectorComponent::Compound(c1)) = components_one.back() {
components_one.get(components_one.len() - 1) if let Some(ComplexSelectorComponent::Compound(c2)) = components_two.back() {
{
if let Some(ComplexSelectorComponent::Compound(c2)) =
components_two.get(components_two.len() - 1)
{
if c2.is_super_selector(c1, &None) { if c2.is_super_selector(c1, &None) {
components_two.pop_back(); components_two.pop_back();
} }
@ -561,12 +549,8 @@ fn merge_final_combinators(
} }
(None, Some(combinator_two)) => { (None, Some(combinator_two)) => {
if *combinator_two == Combinator::Child && !components_one.is_empty() { if *combinator_two == Combinator::Child && !components_one.is_empty() {
if let Some(ComplexSelectorComponent::Compound(c1)) = if let Some(ComplexSelectorComponent::Compound(c1)) = components_one.back() {
components_one.get(components_one.len() - 1) if let Some(ComplexSelectorComponent::Compound(c2)) = components_two.back() {
{
if let Some(ComplexSelectorComponent::Compound(c2)) =
components_two.get(components_two.len() - 1)
{
if c1.is_super_selector(c2, &None) { if c1.is_super_selector(c2, &None) {
components_one.pop_back(); components_one.pop_back();
} }