From 5bd1e95236320aed60fb29ca1e93b9595d4aeeec Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 22 Sep 2010 16:46:18 -0400 Subject: [PATCH] Speedup Device table delta computation for common cases --- src/hb-ot-layout-common-private.hh | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/hb-ot-layout-common-private.hh b/src/hb-ot-layout-common-private.hh index c4a4055..edd08c8 100644 --- a/src/hb-ot-layout-common-private.hh +++ b/src/hb-ot-layout-common-private.hh @@ -1,5 +1,6 @@ /* * Copyright (C) 2007,2008,2009 Red Hat, Inc. + * Copyright (C) 2010 Google, Inc. * * This is part of HarfBuzz, a text shaping library. * @@ -22,6 +23,7 @@ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. * * Red Hat Author(s): Behdad Esfahbod + * Google Author(s): Behdad Esfahbod */ #ifndef HB_OT_LAYOUT_COMMON_PRIVATE_HH @@ -519,15 +521,30 @@ struct ClassDef struct Device { - /* XXX speed up */ inline hb_position_t get_x_delta (hb_ot_layout_context_t *c) const - { return c->font->x_ppem ? get_delta (c->font->x_ppem) * (uint64_t) c->font->x_scale / c->font->x_ppem : 0; } + { return get_delta (c->font->x_ppem, c->font->x_scale); } inline hb_position_t get_y_delta (hb_ot_layout_context_t *c) const - { return c->font->y_ppem ? get_delta (c->font->y_ppem) * (uint64_t) c->font->y_scale / c->font->y_ppem : 0; } + { return get_delta (c->font->y_ppem, c->font->y_scale); } - inline int get_delta (unsigned int ppem_size) const + inline int get_delta (unsigned int ppem, unsigned int scale) const + { + if (!ppem) return 0; + + int pixels = get_delta_pixels (ppem); + + if (!pixels) return 0; + + /* pixels is at most in the -8..7 range. So 64-bit arithmetic is + * not really necessary here. A simple cast to int may just work + * as well. But since this code is not reached that often and + * for the sake of correctness, we do a 64bit operation. */ + return pixels * (int64_t) scale / ppem; + } + + + inline int get_delta_pixels (unsigned int ppem_size) const { unsigned int f = deltaFormat; if (unlikely (f < 1 || f > 3)) -- 2.7.4