From 44251d9dbb411b5e915d28a8c10c3b34cb42abfd Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Sun, 10 Dec 2017 14:00:18 +0100 Subject: [PATCH] Refactor darwin code The ascent calculation on darwin was more complicated than it needed to be. By running a `.ceil()` instead of adding one, checking if it's 0, substracting if it is, and then flooring it, a few instructions could be shaved off. --- font/src/darwin/mod.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/font/src/darwin/mod.rs b/font/src/darwin/mod.rs index 56685dd5..7dde899a 100644 --- a/font/src/darwin/mod.rs +++ b/font/src/darwin/mod.rs @@ -475,13 +475,11 @@ impl Font { // Get the top of the bounding box let metrics = self.metrics(); let height = metrics.line_height; - let mut ascent = height - self.ct_font.descent() + 1.; - if ascent.floor() == ascent { - // Fix off-by-one with an exact X.0 ascent - ascent -= 1.; - } + let ascent = (height - self.ct_font.descent()).ceil(); + // Get the width of the cell let width = self.glyph_advance('0') as i32; + // Return the new custom glyph if character == super::BEAM_CURSOR_CHAR { return super::get_beam_cursor_glyph(ascent as i32, height as i32, width);