[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.
This commit is contained in:
Behdad Esfahbod 2019-07-05 13:18:05 -07:00
parent 144326e215
commit 0d425e1eea
1 changed files with 4 additions and 2 deletions

View File

@ -609,9 +609,11 @@ struct hb_font_t
hb_position_t em_scale (int16_t v, int scale) 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; 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); return (hb_position_t) (scaled / upem);
} }
hb_position_t em_scalef (float v, int scale) hb_position_t em_scalef (float v, int scale)