Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
Use vec
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Sep 27, 2022
1 parent 11b75e8 commit 90f7538
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions crates/rome_js_formatter/src/utils/member_chain/groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::collections::VecDeque;
#[derive(Default)]
pub(super) struct MemberChainGroupsBuilder {
/// keeps track of the groups created
groups: VecDeque<MemberChainGroup>,
groups: Vec<MemberChainGroup>,
/// keeps track of the current group that is being created/updated
current_group: Option<MemberChainGroup>,
}
Expand Down Expand Up @@ -49,15 +49,15 @@ 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);
}
}

pub(super) fn finish(self) -> TailChainGroups {
let mut groups = self.groups;

if let Some(group) = self.current_group {
groups.push_back(group);
groups.push(group);
}

TailChainGroups { groups }
Expand All @@ -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<MemberChainGroup>,
groups: Vec<MemberChainGroup>,
}

impl TailChainGroups {
Expand All @@ -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<MemberChainGroup> {
self.groups.pop_front()
match self.groups.len() {
0 => None,
_ => Some(self.groups.remove(0)),
}
}

/// Checks if the groups contain comments.
Expand Down Expand Up @@ -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<bool> {
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);
}
Expand Down

0 comments on commit 90f7538

Please sign in to comment.