diff --git a/crates/rome_js_formatter/src/utils/member_chain/groups.rs b/crates/rome_js_formatter/src/utils/member_chain/groups.rs index 572d53357cb0..fb011a197724 100644 --- a/crates/rome_js_formatter/src/utils/member_chain/groups.rs +++ b/crates/rome_js_formatter/src/utils/member_chain/groups.rs @@ -8,7 +8,7 @@ use std::collections::VecDeque; #[derive(Default)] pub(super) struct MemberChainGroupsBuilder { /// keeps track of the groups created - groups: VecDeque, + groups: Vec, /// keeps track of the current group that is being created/updated current_group: Option, } @@ -49,7 +49,7 @@ impl MemberChainGroupsBuilder { /// clears the current group, and adds it to the groups collection pub fn close_group(&mut self) { if let Some(group) = self.current_group.take() { - self.groups.push_back(group); + self.groups.push(group); } } @@ -57,7 +57,7 @@ impl MemberChainGroupsBuilder { let mut groups = self.groups; if let Some(group) = self.current_group { - groups.push_back(group); + groups.push(group); } TailChainGroups { groups } @@ -69,7 +69,7 @@ impl MemberChainGroupsBuilder { /// May be empty if all members are part of the head group #[derive(Clone, Debug)] pub(super) struct TailChainGroups { - groups: VecDeque, + groups: Vec, } impl TailChainGroups { @@ -85,17 +85,20 @@ impl TailChainGroups { /// Returns the first group pub(crate) fn first(&self) -> Option<&MemberChainGroup> { - self.groups.front() + self.groups.first() } /// Returns the last group pub(crate) fn last(&self) -> Option<&MemberChainGroup> { - self.groups.back() + self.groups.last() } /// Removes the first group and returns it pub(super) fn pop_first(&mut self) -> Option { - self.groups.pop_front() + match self.groups.len() { + 0 => None, + _ => Some(self.groups.remove(0)), + } } /// Checks if the groups contain comments. @@ -138,11 +141,7 @@ impl TailChainGroups { /// Test if any group except the last group [break](FormatElements::will_break). pub(super) fn any_except_last_will_break(&self, f: &mut JsFormatter) -> FormatResult { - let mut groups = self.groups.iter(); - // Ignore the last group - groups.next_back(); - - for group in groups { + for group in &self.groups[..self.groups.len().saturating_sub(1)] { if group.will_break(f)? { return Ok(true); }