From e6f7479fe34fb4a7cada61d84c2ed70d1fd565c8 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 28 Jul 2012 18:34:58 -0400 Subject: [PATCH] [GSUB] Simplify would-apply --- src/hb-ot-layout-gsub-table.hh | 71 +++------------------------- src/hb-ot-layout-gsubgpos-private.hh | 24 ++-------- 2 files changed, 11 insertions(+), 84 deletions(-) diff --git a/src/hb-ot-layout-gsub-table.hh b/src/hb-ot-layout-gsub-table.hh index 2cbab3292..d95b69199 100644 --- a/src/hb-ot-layout-gsub-table.hh +++ b/src/hb-ot-layout-gsub-table.hh @@ -55,11 +55,6 @@ struct SingleSubstFormat1 return this+coverage; } - inline bool would_apply (hb_would_apply_context_t *c) const - { - return c->len == 1 && (this+coverage) (c->first) != NOT_COVERED; - } - inline bool apply (hb_apply_context_t *c) const { TRACE_APPLY (); @@ -112,11 +107,6 @@ struct SingleSubstFormat2 return this+coverage; } - inline bool would_apply (hb_would_apply_context_t *c) const - { - return c->len == 1 && (this+coverage) (c->first) != NOT_COVERED; - } - inline bool apply (hb_apply_context_t *c) const { TRACE_APPLY (); @@ -174,15 +164,6 @@ struct SingleSubst } } - inline bool would_apply (hb_would_apply_context_t *c) const - { - switch (u.format) { - case 1: return u.format1.would_apply (c); - case 2: return u.format2.would_apply (c); - default:return false; - } - } - inline bool apply (hb_apply_context_t *c) const { TRACE_APPLY (); @@ -276,11 +257,6 @@ struct MultipleSubstFormat1 return this+coverage; } - inline bool would_apply (hb_would_apply_context_t *c) const - { - return c->len == 1 && (this+coverage) (c->first) != NOT_COVERED; - } - inline bool apply (hb_apply_context_t *c) const { TRACE_APPLY (); @@ -331,14 +307,6 @@ struct MultipleSubst } } - inline bool would_apply (hb_would_apply_context_t *c) const - { - switch (u.format) { - case 1: return u.format1.would_apply (c); - default:return false; - } - } - inline bool apply (hb_apply_context_t *c) const { TRACE_APPLY (); @@ -393,11 +361,6 @@ struct AlternateSubstFormat1 return this+coverage; } - inline bool would_apply (hb_would_apply_context_t *c) const - { - return c->len == 1 && (this+coverage) (c->first) != NOT_COVERED; - } - inline bool apply (hb_apply_context_t *c) const { TRACE_APPLY (); @@ -466,14 +429,6 @@ struct AlternateSubst } } - inline bool would_apply (hb_would_apply_context_t *c) const - { - switch (u.format) { - case 1: return u.format1.would_apply (c); - default:return false; - } - } - inline bool apply (hb_apply_context_t *c) const { TRACE_APPLY (); @@ -675,9 +630,7 @@ struct LigatureSubstFormat1 inline bool would_apply (hb_would_apply_context_t *c) const { - unsigned int index; - return (index = (this+coverage) (c->first)) != NOT_COVERED && - (this+ligatureSet[index]).would_apply (c); + return (this+ligatureSet[(this+coverage) (c->first)]).would_apply (c); } inline bool apply (hb_apply_context_t *c) const @@ -871,11 +824,6 @@ struct ReverseChainSingleSubstFormat1 return this+coverage; } - inline bool would_apply (hb_would_apply_context_t *c) const - { - return c->len == 1 && (this+coverage) (c->first) != NOT_COVERED; - } - inline bool apply (hb_apply_context_t *c) const { TRACE_APPLY (); @@ -958,14 +906,6 @@ struct ReverseChainSingleSubst } } - inline bool would_apply (hb_would_apply_context_t *c) const - { - switch (u.format) { - case 1: return u.format1.would_apply (c); - default:return false; - } - } - inline bool apply (hb_apply_context_t *c) const { TRACE_APPLY (); @@ -1048,15 +988,16 @@ struct SubstLookupSubTable unsigned int lookup_type) const { TRACE_WOULD_APPLY (); + if (get_coverage (lookup_type).get_coverage (c->first) == NOT_COVERED) return false; + if (c->len == 1) return true; /* Done! */ + + /* Only need to look further for lookups that support substitutions + * of input longer than 1. */ switch (lookup_type) { - case Single: return u.single.would_apply (c); - case Multiple: return u.multiple.would_apply (c); - case Alternate: return u.alternate.would_apply (c); case Ligature: return u.ligature.would_apply (c); case Context: return u.context.would_apply (c); case ChainContext: return u.chainContext.would_apply (c); case Extension: return u.extension.would_apply (c); - case ReverseChainSingle: return u.reverseChainContextSingle.would_apply (c); default: return false; } } diff --git a/src/hb-ot-layout-gsubgpos-private.hh b/src/hb-ot-layout-gsubgpos-private.hh index 870916f40..2d6cafca9 100644 --- a/src/hb-ot-layout-gsubgpos-private.hh +++ b/src/hb-ot-layout-gsubgpos-private.hh @@ -677,11 +677,8 @@ struct ContextFormat1 inline bool would_apply (hb_would_apply_context_t *c) const { TRACE_WOULD_APPLY (); - unsigned int index = (this+coverage) (c->first); - if (likely (index == NOT_COVERED)) - return TRACE_RETURN (false); - const RuleSet &rule_set = this+ruleSet[index]; + const RuleSet &rule_set = this+ruleSet[(this+coverage) (c->first)]; struct ContextApplyLookupContext lookup_context = { {match_glyph, NULL}, NULL @@ -752,11 +749,9 @@ struct ContextFormat2 inline bool would_apply (hb_would_apply_context_t *c) const { TRACE_WOULD_APPLY (); - unsigned int index = (this+coverage) (c->first); - if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); const ClassDef &class_def = this+classDef; - index = class_def (c->first); + unsigned int index = class_def (c->first); const RuleSet &rule_set = this+ruleSet[index]; struct ContextApplyLookupContext lookup_context = { {match_class, NULL}, @@ -828,8 +823,6 @@ struct ContextFormat3 inline bool would_apply (hb_would_apply_context_t *c) const { TRACE_WOULD_APPLY (); - unsigned int index = (this+coverage[0]) (c->first); - if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); const LookupRecord *lookupRecord = &StructAtOffset (coverage, coverage[0].static_size * glyphCount); struct ContextApplyLookupContext lookup_context = { @@ -1180,10 +1173,8 @@ struct ChainContextFormat1 inline bool would_apply (hb_would_apply_context_t *c) const { TRACE_WOULD_APPLY (); - unsigned int index = (this+coverage) (c->first); - if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); - const ChainRuleSet &rule_set = this+ruleSet[index]; + const ChainRuleSet &rule_set = this+ruleSet[(this+coverage) (c->first)]; struct ChainContextApplyLookupContext lookup_context = { {match_glyph, NULL}, {NULL, NULL, NULL} @@ -1256,12 +1247,10 @@ struct ChainContextFormat2 inline bool would_apply (hb_would_apply_context_t *c) const { TRACE_WOULD_APPLY (); - unsigned int index = (this+coverage) (c->first); - if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); const ClassDef &input_class_def = this+inputClassDef; - index = input_class_def (c->first); + unsigned int index = input_class_def (c->first); const ChainRuleSet &rule_set = this+ruleSet[index]; struct ChainContextApplyLookupContext lookup_context = { {match_class, NULL}, @@ -1359,11 +1348,8 @@ struct ChainContextFormat3 inline bool would_apply (hb_would_apply_context_t *c) const { TRACE_WOULD_APPLY (); - const OffsetArrayOf &input = StructAfter > (backtrack); - - unsigned int index = (this+input[0]) (c->first); - if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); + const OffsetArrayOf &input = StructAfter > (backtrack); const OffsetArrayOf &lookahead = StructAfter > (input); const ArrayOf &lookup = StructAfter > (lookahead); struct ChainContextApplyLookupContext lookup_context = {