[shape-plan] Refactor more

This commit is contained in:
Behdad Esfahbod 2018-11-12 18:18:20 -05:00
parent 1082338525
commit 8284cb9fb3
1 changed files with 26 additions and 20 deletions

View File

@ -411,10 +411,9 @@ hb_shape_plan_key_equal (const hb_shape_plan_key_t *key1,
} }
static inline bool static inline bool
hb_shape_plan_key_has_non_global_user_features (const hb_shape_plan_key_t *key) _has_non_global_user_features (const hb_feature_t *user_features,
unsigned int num_user_features)
{ {
unsigned int num_user_features = key->num_user_features;
const hb_feature_t *user_features = key->user_features;
while (num_user_features) while (num_user_features)
{ {
if (user_features->start != HB_FEATURE_GLOBAL_START || if (user_features->start != HB_FEATURE_GLOBAL_START ||
@ -427,16 +426,20 @@ hb_shape_plan_key_has_non_global_user_features (const hb_shape_plan_key_t *key)
} }
static inline bool static inline bool
hb_shape_plan_key_has_coords (const hb_shape_plan_key_t *key) _has_coords (const int *coords,
unsigned int num_coords)
{ {
return key->num_coords; return num_coords;
} }
static inline bool static inline bool
hb_shape_plan_key_dont_cache (const hb_shape_plan_key_t *key) _dont_cache (const hb_feature_t *user_features,
unsigned int num_user_features,
const int *coords,
unsigned int num_coords)
{ {
return hb_shape_plan_key_has_non_global_user_features (key) || return _has_non_global_user_features (user_features, num_user_features) ||
hb_shape_plan_key_has_coords (key); _has_coords (coords, num_coords);
} }
/** /**
@ -481,6 +484,15 @@ hb_shape_plan_create_cached2 (hb_face_t *face,
num_user_features, num_user_features,
shaper_list); shaper_list);
retry:
hb_face_t::plan_node_t *cached_plan_nodes = face->shape_plans;
bool dont_cache = _dont_cache (user_features, num_user_features,
coords, num_coords) ||
hb_object_is_inert (face);
if (!dont_cache)
{
hb_shape_plan_key_t key; hb_shape_plan_key_t key;
if (!key.init (false, if (!key.init (false,
face, face,
@ -492,19 +504,13 @@ hb_shape_plan_create_cached2 (hb_face_t *face,
shaper_list)) shaper_list))
return hb_shape_plan_get_empty (); return hb_shape_plan_get_empty ();
retry:
hb_face_t::plan_node_t *cached_plan_nodes = face->shape_plans;
bool dont_cache = hb_shape_plan_key_dont_cache (&key) ||
hb_object_is_inert (face);
if (!dont_cache)
for (hb_face_t::plan_node_t *node = cached_plan_nodes; node; node = node->next) for (hb_face_t::plan_node_t *node = cached_plan_nodes; node; node = node->next)
if (hb_shape_plan_key_equal (&node->shape_plan->key, &key)) if (hb_shape_plan_key_equal (&node->shape_plan->key, &key))
{ {
DEBUG_MSG_FUNC (SHAPE_PLAN, node->shape_plan, "fulfilled from cache"); DEBUG_MSG_FUNC (SHAPE_PLAN, node->shape_plan, "fulfilled from cache");
return hb_shape_plan_reference (node->shape_plan); return hb_shape_plan_reference (node->shape_plan);
} }
}
hb_shape_plan_t *shape_plan = hb_shape_plan_create2 (face, props, hb_shape_plan_t *shape_plan = hb_shape_plan_create2 (face, props,
user_features, num_user_features, user_features, num_user_features,