Skip to content

Commit

Permalink
perf(layout): avoid allocating memory when using split ergonomic utils (
Browse files Browse the repository at this point in the history
#1105)

Don't create intermediate vec in `Layout::areas` and
`Layout::spacers` when there's no need for one.
  • Loading branch information
tranzystorekk committed May 13, 2024
1 parent 839cca2 commit 1a4bb1c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/layout/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ impl Layout {
/// # }
pub fn areas<const N: usize>(&self, area: Rect) -> [Rect; N] {
let (areas, _) = self.split_with_spacers(area);
areas.to_vec().try_into().expect("invalid number of rects")
areas.as_ref().try_into().expect("invalid number of rects")
}

/// Split the rect into a number of sub-rects according to the given [`Layout`] and return just
Expand Down Expand Up @@ -482,7 +482,7 @@ impl Layout {
pub fn spacers<const N: usize>(&self, area: Rect) -> [Rect; N] {
let (_, spacers) = self.split_with_spacers(area);
spacers
.to_vec()
.as_ref()
.try_into()
.expect("invalid number of rects")
}
Expand Down

0 comments on commit 1a4bb1c

Please sign in to comment.