summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeedehai <18319900+Leedehai@users.noreply.github.com>2023-05-19 10:48:57 -0400
committerGitHub <noreply@github.com>2023-05-19 16:48:57 +0200
commit74b818fe40cb9efeb7af09133f74360bf835c105 (patch)
tree86475a6467fc8330fc524334be5b6cf36740a7fc
parent42f1586880d323442d7bf7cc2ec7bec70375b4d8 (diff)
Reduce redundant ops when computing sup/sub shifts (#1190)
-rw-r--r--library/src/math/attach.rs24
1 files changed, 13 insertions, 11 deletions
diff --git a/library/src/math/attach.rs b/library/src/math/attach.rs
index 67331908..bb6dca5f 100644
--- a/library/src/math/attach.rs
+++ b/library/src/math/attach.rs
@@ -143,6 +143,12 @@ impl LayoutMath for LimitsElem {
}
}
+macro_rules! measure {
+ ($e: ident, $attr: ident) => {
+ $e.as_ref().map(|e| e.$attr()).unwrap_or_default()
+ };
+}
+
/// Layout the attachments.
fn layout_attachments(
ctx: &mut MathContext,
@@ -158,12 +164,6 @@ fn layout_attachments(
(base.width(), base.ascent(), base.descent());
let base_class = base.class().unwrap_or(MathClass::Normal);
- macro_rules! measure {
- ($e: ident, $attr: ident) => {
- $e.as_ref().map(|e| e.$attr()).unwrap_or_default()
- };
- }
-
let ascent = base_ascent
.max(shift_up + measure!(tr, ascent))
.max(shift_up + measure!(tl, ascent))
@@ -301,22 +301,24 @@ fn compute_shifts_up_and_down(
let mut shift_down = Abs::zero();
let is_char_box = is_character_box(base);
- for e in [tl, tr].into_iter().flatten() {
+ if tl.is_some() || tr.is_some() {
let ascent = match &base {
MathFragment::Frame(frame) => frame.base_ascent,
_ => base.ascent(),
};
-
shift_up = shift_up
.max(sup_shift_up)
.max(if is_char_box { Abs::zero() } else { ascent - sup_drop_max })
- .max(sup_bottom_min + e.descent());
+ .max(sup_bottom_min + measure!(tl, descent))
+ .max(sup_bottom_min + measure!(tr, descent));
}
- for e in [bl, br].into_iter().flatten() {
+
+ if bl.is_some() || br.is_some() {
shift_down = shift_down
.max(sub_shift_down)
.max(if is_char_box { Abs::zero() } else { base.descent() + sub_drop_min })
- .max(e.ascent() - sub_top_max);
+ .max(measure!(bl, ascent) - sub_top_max)
+ .max(measure!(br, ascent) - sub_top_max);
}
for (sup, sub) in [(tl, bl), (tr, br)] {