diff options
| author | Marek Barvíř <barvirm@gmail.com> | 2023-04-01 15:53:13 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-01 15:53:13 +0200 |
| commit | 5e5b1bba510179a1c50f34b3a239f1913e7be78d (patch) | |
| tree | 520058fd817fcd4b5f3e523c5f665fed6916b098 /library/src/layout | |
| parent | 9eb6174b22fa4824869fc5e923b96847c2968462 (diff) | |
Needless clone, borrows, casts and lifetimes (#504)
Diffstat (limited to 'library/src/layout')
| -rw-r--r-- | library/src/layout/flow.rs | 4 | ||||
| -rw-r--r-- | library/src/layout/fragment.rs | 5 | ||||
| -rw-r--r-- | library/src/layout/grid.rs | 2 | ||||
| -rw-r--r-- | library/src/layout/list.rs | 2 | ||||
| -rw-r--r-- | library/src/layout/mod.rs | 10 | ||||
| -rw-r--r-- | library/src/layout/par.rs | 9 | ||||
| -rw-r--r-- | library/src/layout/stack.rs | 2 |
7 files changed, 20 insertions, 14 deletions
diff --git a/library/src/layout/flow.rs b/library/src/layout/flow.rs index da2ddba6..cd7b1f60 100644 --- a/library/src/layout/flow.rs +++ b/library/src/layout/flow.rs @@ -30,7 +30,7 @@ impl Layout for FlowElem { let mut styles = styles; if let Some((elem, map)) = child.to_styled() { child = elem; - styles = outer.chain(&map); + styles = outer.chain(map); } if let Some(elem) = child.to::<VElem>() { @@ -54,7 +54,7 @@ impl Layout for FlowElem { true, )); } else if child.can::<dyn Layout>() { - layouter.layout_multiple(vt, &child, styles)?; + layouter.layout_multiple(vt, child, styles)?; } else if child.is::<ColbreakElem>() { if !layouter.regions.backlog.is_empty() || layouter.regions.last.is_some() { diff --git a/library/src/layout/fragment.rs b/library/src/layout/fragment.rs index d1f6b524..3550df2a 100644 --- a/library/src/layout/fragment.rs +++ b/library/src/layout/fragment.rs @@ -15,6 +15,11 @@ impl Fragment { Self(frames) } + /// Return `true` if the length is 0. + pub fn is_empty(&self) -> bool { + self.0.is_empty() + } + /// The number of frames in the fragment. pub fn len(&self) -> usize { self.0.len() diff --git a/library/src/layout/grid.rs b/library/src/layout/grid.rs index e0c8b684..01bf7e30 100644 --- a/library/src/layout/grid.rs +++ b/library/src/layout/grid.rs @@ -267,7 +267,7 @@ impl<'a, 'v> GridLayouter<'a, 'v> { // We use these regions for auto row measurement. Since at that moment, // columns are already sized, we can enable horizontal expansion. - let mut regions = regions.clone(); + let mut regions = regions; regions.expand = Axes::new(true, false); Self { diff --git a/library/src/layout/list.rs b/library/src/layout/list.rs index 9f8d5a92..6cb1bc7e 100644 --- a/library/src/layout/list.rs +++ b/library/src/layout/list.rs @@ -197,7 +197,7 @@ cast_from_value! { ListMarker, v: Content => Self::Content(vec![v]), array: Array => { - if array.len() == 0 { + if array.is_empty() { Err("array must contain at least one marker")?; } Self::Content(array.into_iter().map(Value::display).collect()) diff --git a/library/src/layout/mod.rs b/library/src/layout/mod.rs index 1e437723..e93b2e02 100644 --- a/library/src/layout/mod.rs +++ b/library/src/layout/mod.rs @@ -172,7 +172,7 @@ fn realize_root<'a>( return Ok((content.clone(), styles)); } - let mut builder = Builder::new(vt, &scratch, true); + let mut builder = Builder::new(vt, scratch, true); builder.accept(content, styles)?; builder.interrupt_page(Some(styles))?; let (pages, shared) = builder.doc.unwrap().pages.finish(); @@ -197,7 +197,7 @@ fn realize_block<'a>( return Ok((content.clone(), styles)); } - let mut builder = Builder::new(vt, &scratch, false); + let mut builder = Builder::new(vt, scratch, false); builder.accept(content, styles)?; builder.interrupt_par()?; let (children, shared) = builder.flow.0.finish(); @@ -314,7 +314,7 @@ impl<'a, 'v, 't> Builder<'a, 'v, 't> { ) -> SourceResult<()> { let stored = self.scratch.styles.alloc(styles); let styles = stored.chain(map); - self.interrupt_style(&map, None)?; + self.interrupt_style(map, None)?; self.accept(elem, styles)?; self.interrupt_style(map, Some(styles))?; Ok(()) @@ -468,9 +468,9 @@ impl<'a> FlowBuilder<'a> { let above = BlockElem::above_in(styles); let below = BlockElem::below_in(styles); - self.0.push(above.clone().pack(), styles); + self.0.push(above.pack(), styles); self.0.push(content.clone(), styles); - self.0.push(below.clone().pack(), styles); + self.0.push(below.pack(), styles); return true; } diff --git a/library/src/layout/par.rs b/library/src/layout/par.rs index dc445c86..7e43b43f 100644 --- a/library/src/layout/par.rs +++ b/library/src/layout/par.rs @@ -365,12 +365,13 @@ impl<'a> Item<'a> { } /// Maps byte offsets back to spans. +#[derive(Default)] pub struct SpanMapper(Vec<(usize, Span)>); impl SpanMapper { /// Create a new span mapper. pub fn new() -> Self { - Self(vec![]) + Self::default() } /// Push a span for a segment with the given length. @@ -745,8 +746,8 @@ fn is_compatible(a: Script, b: Script) -> bool { /// Get a style property, but only if it is the same for all children of the /// paragraph. -fn shared_get<'a, T: PartialEq>( - styles: StyleChain<'a>, +fn shared_get<T: PartialEq>( + styles: StyleChain<'_>, children: &[Content], getter: fn(StyleChain) -> T, ) -> Option<T> { @@ -754,7 +755,7 @@ fn shared_get<'a, T: PartialEq>( children .iter() .filter_map(|child| child.to_styled()) - .all(|(_, local)| getter(styles.chain(&local)) == value) + .all(|(_, local)| getter(styles.chain(local)) == value) .then(|| value) } diff --git a/library/src/layout/stack.rs b/library/src/layout/stack.rs index c85eda2d..8146114a 100644 --- a/library/src/layout/stack.rs +++ b/library/src/layout/stack.rs @@ -198,7 +198,7 @@ impl<'a> StackLayouter<'a> { let aligns = if let Some(align) = block.to::<AlignElem>() { align.alignment(styles) } else if let Some((_, local)) = block.to_styled() { - AlignElem::alignment_in(styles.chain(&local)) + AlignElem::alignment_in(styles.chain(local)) } else { AlignElem::alignment_in(styles) } |
