From 0d425e1eeaea97bf5e4fc9ce40e549332bc0cea1 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 5 Jul 2019 13:18:05 -0700 Subject: [PATCH] [ot-font] Optimize rounding Part of https://github.com/harfbuzz/harfbuzz/issues/1801 The assumption that compiler optimizes "upem/2" to a shift only works if upem is unsigned... Anyway, spoon-feed the compiler. --- src/hb-font.hh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/hb-font.hh b/src/hb-font.hh index 3b917d1..d807874 100644 --- a/src/hb-font.hh +++ b/src/hb-font.hh @@ -609,9 +609,11 @@ struct hb_font_t hb_position_t em_scale (int16_t v, int scale) { - int upem = face->get_upem (); + signed upem = face->get_upem (); + signed upem2 = upem >> 1; int64_t scaled = v * (int64_t) scale; - scaled += scaled >= 0 ? upem/2 : -upem/2; /* Round. */ + + scaled += scaled >= 0 ? upem2 : -upem2; /* Round. */ return (hb_position_t) (scaled / upem); } hb_position_t em_scalef (float v, int scale) -- 2.7.4