From b41cce191ca792e4622d859f3f8b84d45f9e070c Mon Sep 17 00:00:00 2001 From: Matt Fellenz Date: Mon, 1 May 2023 04:29:59 -0700 Subject: [PATCH] Optimize `.count() > 1` check (#1053) This can be trivially optimized to `.nth(1).is_some()` which obviates evaluating every element in the iterator. --- library/src/math/ctx.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/src/math/ctx.rs b/library/src/math/ctx.rs index 562f0ba9f..a6487476a 100644 --- a/library/src/math/ctx.rs +++ b/library/src/math/ctx.rs @@ -155,7 +155,7 @@ impl<'a, 'b, 'v> MathContext<'a, 'b, 'v> { FrameFragment::new(self, frame).into() } else { // Anything else is handled by Typst's standard text layout. - let spaced = text.graphemes(true).count() > 1; + let spaced = text.graphemes(true).nth(1).is_some(); let mut style = self.style; if self.style.italic == Smart::Auto { style = style.with_italic(false);