[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 committed 2019-07-05 13:42:02 -07:00
1 parent 144326e215
commit 0d425e1eea
1 file changed
+4 -2
+4 -2
View File
@@ -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)