提交 aa3d7adc 编写于 作者: B Behdad Esfahbod

[HB] More churning towards ChainContext lookups

上级 48f16ed9
...@@ -296,7 +296,7 @@ struct Coverage { ...@@ -296,7 +296,7 @@ struct Coverage {
} }
} }
unsigned int operator() (hb_codepoint_t glyph_id) const { inline unsigned int operator() (hb_codepoint_t glyph_id) const {
return get_coverage (glyph_id); return get_coverage (glyph_id);
} }
...@@ -382,6 +382,10 @@ struct ClassDef { ...@@ -382,6 +382,10 @@ struct ClassDef {
} }
} }
inline unsigned int operator() (hb_codepoint_t glyph_id) const {
return get_class (glyph_id);
}
private: private:
union { union {
USHORT format; /* Format identifier */ USHORT format; /* Format identifier */
......
...@@ -49,7 +49,7 @@ struct SingleSubstFormat1 { ...@@ -49,7 +49,7 @@ struct SingleSubstFormat1 {
inline bool single_substitute (hb_codepoint_t &glyph_id) const { inline bool single_substitute (hb_codepoint_t &glyph_id) const {
unsigned int index = (this+coverage) (glyph_id); unsigned int index = (this+coverage) (glyph_id);
if (NOT_COVERED == index) if (G_LIKELY (index == NOT_COVERED))
return false; return false;
glyph_id += deltaGlyphID; glyph_id += deltaGlyphID;
...@@ -76,8 +76,10 @@ struct SingleSubstFormat2 { ...@@ -76,8 +76,10 @@ struct SingleSubstFormat2 {
inline bool single_substitute (hb_codepoint_t &glyph_id) const { inline bool single_substitute (hb_codepoint_t &glyph_id) const {
unsigned int index = (this+coverage) (glyph_id); unsigned int index = (this+coverage) (glyph_id);
if (G_LIKELY (index == NOT_COVERED))
return false;
if (index >= substitute.len) if (G_UNLIKELY (index >= substitute.len))
return false; return false;
glyph_id = substitute[index]; glyph_id = substitute[index];
...@@ -187,6 +189,9 @@ struct MultipleSubstFormat1 { ...@@ -187,6 +189,9 @@ struct MultipleSubstFormat1 {
inline bool substitute (LOOKUP_ARGS_DEF) const { inline bool substitute (LOOKUP_ARGS_DEF) const {
unsigned int index = (this+coverage) (IN_CURGLYPH ()); unsigned int index = (this+coverage) (IN_CURGLYPH ());
if (G_LIKELY (index == NOT_COVERED))
return false;
return (this+sequence[index]).substitute_sequence (LOOKUP_ARGS); return (this+sequence[index]).substitute_sequence (LOOKUP_ARGS);
} }
...@@ -238,6 +243,9 @@ struct AlternateSubstFormat1 { ...@@ -238,6 +243,9 @@ struct AlternateSubstFormat1 {
hb_codepoint_t glyph_id = IN_CURGLYPH (); hb_codepoint_t glyph_id = IN_CURGLYPH ();
unsigned int index = (this+coverage) (glyph_id); unsigned int index = (this+coverage) (glyph_id);
if (G_LIKELY (index == NOT_COVERED))
return false;
const AlternateSet &alt_set = this+alternateSet[index]; const AlternateSet &alt_set = this+alternateSet[index];
if (HB_UNLIKELY (!alt_set.len)) if (HB_UNLIKELY (!alt_set.len))
...@@ -421,6 +429,9 @@ struct LigatureSubstFormat1 { ...@@ -421,6 +429,9 @@ struct LigatureSubstFormat1 {
property & LookupFlag::MarkAttachmentType); property & LookupFlag::MarkAttachmentType);
unsigned int index = (this+coverage) (glyph_id); unsigned int index = (this+coverage) (glyph_id);
if (G_LIKELY (index == NOT_COVERED))
return false;
const LigatureSet &lig_set = this+ligatureSet[index]; const LigatureSet &lig_set = this+ligatureSet[index];
return lig_set.substitute_ligature (LOOKUP_ARGS, first_is_mark); return lig_set.substitute_ligature (LOOKUP_ARGS, first_is_mark);
} }
......
...@@ -155,8 +155,6 @@ struct Rule { ...@@ -155,8 +155,6 @@ struct Rule {
friend struct RuleSet; friend struct RuleSet;
private: private:
DEFINE_ARRAY_TYPE (USHORT, input, (inputCount ? inputCount - 1 : 0));
inline bool apply (LOOKUP_ARGS_DEF, ContextLookupContext &context) const { inline bool apply (LOOKUP_ARGS_DEF, ContextLookupContext &context) const {
const LookupRecord *record = (const LookupRecord *) ((const char *) input + sizeof (input[0]) * (inputCount ? inputCount - 1 : 0)); const LookupRecord *record = (const LookupRecord *) ((const char *) input + sizeof (input[0]) * (inputCount ? inputCount - 1 : 0));
return context_lookup (LOOKUP_ARGS, return context_lookup (LOOKUP_ARGS,
...@@ -174,7 +172,7 @@ struct Rule { ...@@ -174,7 +172,7 @@ struct Rule {
USHORT lookupCount; /* Number of LookupRecords */ USHORT lookupCount; /* Number of LookupRecords */
USHORT input[]; /* Array of match inputs--start with USHORT input[]; /* Array of match inputs--start with
* second glyph */ * second glyph */
LookupRecord lookupRecord[]; /* Array of LookupRecords--in LookupRecord lookupRecordX[]; /* Array of LookupRecords--in
* design order */ * design order */
}; };
ASSERT_SIZE (Rule, 4); ASSERT_SIZE (Rule, 4);
...@@ -207,6 +205,9 @@ struct ContextFormat1 { ...@@ -207,6 +205,9 @@ struct ContextFormat1 {
inline bool apply (LOOKUP_ARGS_DEF, apply_lookup_func_t apply_func) const { inline bool apply (LOOKUP_ARGS_DEF, apply_lookup_func_t apply_func) const {
unsigned int index = (this+coverage) (IN_CURGLYPH ()); unsigned int index = (this+coverage) (IN_CURGLYPH ());
if (G_LIKELY (index == NOT_COVERED))
return false;
const RuleSet &rule_set = this+ruleSet[index]; const RuleSet &rule_set = this+ruleSet[index];
struct ContextLookupContext context = { struct ContextLookupContext context = {
{match_glyph, apply_func}, {match_glyph, apply_func},
...@@ -235,13 +236,18 @@ struct ContextFormat2 { ...@@ -235,13 +236,18 @@ struct ContextFormat2 {
inline bool apply (LOOKUP_ARGS_DEF, apply_lookup_func_t apply_func) const { inline bool apply (LOOKUP_ARGS_DEF, apply_lookup_func_t apply_func) const {
unsigned int index = (this+coverage) (IN_CURGLYPH ()); unsigned int index = (this+coverage) (IN_CURGLYPH ());
if (G_LIKELY (index == NOT_COVERED))
return false;
const ClassDef &class_def = this+classDef;
index = class_def (IN_CURGLYPH ());
const RuleSet &rule_set = this+ruleSet[index]; const RuleSet &rule_set = this+ruleSet[index];
/* LONGTERMTODO: Old code fetches glyph classes at most once and caches /* LONGTERMTODO: Old code fetches glyph classes at most once and caches
* them across subrule lookups. Not sure it's worth it. * them across subrule lookups. Not sure it's worth it.
*/ */
struct ContextLookupContext context = { struct ContextLookupContext context = {
{match_class, apply_func}, {match_class, apply_func},
(char *) &(this+classDef) (char *) &class_def
}; };
return rule_set.apply (LOOKUP_ARGS, context); return rule_set.apply (LOOKUP_ARGS, context);
} }
...@@ -267,9 +273,6 @@ struct ContextFormat3 { ...@@ -267,9 +273,6 @@ struct ContextFormat3 {
private: private:
/* Coverage tables, in glyph sequence order */
DEFINE_OFFSET_ARRAY_TYPE (Coverage, coverage, glyphCount);
inline bool apply_coverage (LOOKUP_ARGS_DEF, apply_lookup_func_t apply_func) const { inline bool apply_coverage (LOOKUP_ARGS_DEF, apply_lookup_func_t apply_func) const {
const LookupRecord *record = (const LookupRecord *) ((const char *) coverage + sizeof (coverage[0]) * glyphCount); const LookupRecord *record = (const LookupRecord *) ((const char *) coverage + sizeof (coverage[0]) * glyphCount);
struct ContextLookupContext context = { struct ContextLookupContext context = {
...@@ -286,7 +289,8 @@ struct ContextFormat3 { ...@@ -286,7 +289,8 @@ struct ContextFormat3 {
inline bool apply (LOOKUP_ARGS_DEF, apply_lookup_func_t apply_func) const { inline bool apply (LOOKUP_ARGS_DEF, apply_lookup_func_t apply_func) const {
if ((*this)[0].get_coverage (IN_CURGLYPH () == NOT_COVERED)) unsigned int index = (this+coverage[0]) (IN_CURGLYPH ());
if (G_LIKELY (index == NOT_COVERED))
return false; return false;
return apply_coverage (LOOKUP_ARGS, apply_func); return apply_coverage (LOOKUP_ARGS, apply_func);
...@@ -297,11 +301,10 @@ struct ContextFormat3 { ...@@ -297,11 +301,10 @@ struct ContextFormat3 {
USHORT glyphCount; /* Number of glyphs in the input glyph USHORT glyphCount; /* Number of glyphs in the input glyph
* sequence */ * sequence */
USHORT lookupCount; /* Number of LookupRecords */ USHORT lookupCount; /* Number of LookupRecords */
Offset coverage[]; /* Array of offsets to Coverage OffsetTo<Coverage>
* table--from beginning of coverage[]; /* Array of offsets to Coverage
* table--in glyph * table in glyph sequence order */
* sequence order */ LookupRecord lookupRecordX[]; /* Array of LookupRecords--in
LookupRecord lookupRecord[]; /* Array of LookupRecords--in
* design order */ * design order */
}; };
ASSERT_SIZE (ContextFormat3, 6); ASSERT_SIZE (ContextFormat3, 6);
...@@ -337,9 +340,22 @@ struct ChainContextLookupContext { ...@@ -337,9 +340,22 @@ struct ChainContextLookupContext {
}; };
struct ChainRule { struct ChainRule {
/* TODO */
friend struct ChainRuleSet;
private:
inline bool apply (LOOKUP_ARGS_DEF, ChainContextLookupContext &context) const {
return false;
// const LookupRecord *record = (const LookupRecord *) ((const char *) input + sizeof (input[0]) * (inputCount ? inputCount - 1 : 0));
// return context_lookup (LOOKUP_ARGS,
// inputCount,
// input,
// lookupCount,
// record,
// context);
}
private: private:
USHORT backtrackCount; /* Total number of glyphs in the USHORT backtrackCount; /* Total number of glyphs in the
...@@ -349,24 +365,23 @@ struct ChainRule { ...@@ -349,24 +365,23 @@ struct ChainRule {
USHORT backtrack[]; /* Array of backtracking values USHORT backtrack[]; /* Array of backtracking values
* (to be matched before the input * (to be matched before the input
* sequence) */ * sequence) */
USHORT inputCount; /* Total number of values in the input USHORT inputCountX; /* Total number of values in the input
* sequence (includes the first glyph) */ * sequence (includes the first glyph) */
USHORT input[]; /* Array of input values (start with USHORT inputX[]; /* Array of input values (start with
* second glyph) */ * second glyph) */
USHORT lookaheadCount; /* Total number of glyphs in the look USHORT lookaheadCountX; /* Total number of glyphs in the look
* ahead sequence (number of glyphs to * ahead sequence (number of glyphs to
* be matched after the input sequence) */ * be matched after the input sequence) */
USHORT lookahead[]; /* Array of lookahead values's (to be USHORT lookaheadX[]; /* Array of lookahead values's (to be
* matched after the input sequence) */ * matched after the input sequence) */
USHORT lookupCount; /* Number of LookupRecords */ USHORT lookupCountX; /* Number of LookupRecords */
LookupRecord lookupRecord[]; /* Array of LookupRecords--in LookupRecord lookupRecordX[]; /* Array of LookupRecords--in
* design order) */ * design order) */
}; };
ASSERT_SIZE (ChainRule, 8); ASSERT_SIZE (ChainRule, 8);
struct ChainRuleSet { struct ChainRuleSet {
/*
inline bool apply (LOOKUP_ARGS_DEF, ChainContextLookupContext &context) const { inline bool apply (LOOKUP_ARGS_DEF, ChainContextLookupContext &context) const {
unsigned int num_rules = rule.len; unsigned int num_rules = rule.len;
...@@ -377,7 +392,6 @@ struct ChainRuleSet { ...@@ -377,7 +392,6 @@ struct ChainRuleSet {
return false; return false;
} }
*/
private: private:
OffsetArrayOf<ChainRule> OffsetArrayOf<ChainRule>
...@@ -392,30 +406,26 @@ struct ChainContextFormat1 { ...@@ -392,30 +406,26 @@ struct ChainContextFormat1 {
private: private:
inline bool apply (LOOKUP_ARGS_DEF, apply_lookup_func_t apply_func) const { inline bool apply (LOOKUP_ARGS_DEF, apply_lookup_func_t apply_func) const {
/* TODO */
// unsigned int index = (this+coverage) (IN_CURGLYPH ());
// const RuleSet &rule_set = this+ruleSet[index];
// struct ContextLookupContext context = {
// glyph_match, NULL,
// apply_func
// };
// return rule_set.apply (LOOKUP_ARGS, context);
return false;
}
unsigned int index = (this+coverage) (IN_CURGLYPH ());
if (G_LIKELY (index == NOT_COVERED))
return false;
const ChainRuleSet &rule_set = this+ruleSet[index];
struct ChainContextLookupContext context = {
{match_glyph, apply_func},
{NULL, NULL, NULL}
};
return rule_set.apply (LOOKUP_ARGS, context);
}
private: private:
USHORT format; /* Format identifier--format = 1 */ USHORT format; /* Format identifier--format = 1 */
OffsetTo<Coverage> OffsetTo<Coverage>
coverage; /* Offset to Coverage table--from coverage; /* Offset to Coverage table--from
* beginning of table */ * beginning of table */
USHORT chainRuleSetCount; /* Number of ChainRuleSet OffsetArrayOf<ChainRuleSet>
* tables--must equal GlyphCount in ruleSet; /* Array of ChainRuleSet tables
* Coverage table */ * ordered by Coverage Index */
Offset chainRuleSet[]; /* Array of offsets to ChainRuleSet
* tables--from beginning of
* table--ordered by Coverage Index */
}; };
ASSERT_SIZE (ChainContextFormat1, 6); ASSERT_SIZE (ChainContextFormat1, 6);
...@@ -426,37 +436,48 @@ struct ChainContextFormat2 { ...@@ -426,37 +436,48 @@ struct ChainContextFormat2 {
private: private:
inline bool apply (LOOKUP_ARGS_DEF, apply_lookup_func_t apply_func) const { inline bool apply (LOOKUP_ARGS_DEF, apply_lookup_func_t apply_func) const {
// unsigned int index = (this+coverage) (IN_CURGLYPH ()); unsigned int index = (this+coverage) (IN_CURGLYPH ());
// const RuleSet &rule_set = this+ruleSet[index]; if (G_LIKELY (index == NOT_COVERED))
return false;
const ClassDef &backtrack_class_def = this+backtrackClassDef;
const ClassDef &input_class_def = this+inputClassDef;
const ClassDef &lookahead_class_def = this+lookaheadClassDef;
index = input_class_def (IN_CURGLYPH ());
const ChainRuleSet &rule_set = this+ruleSet[index];
/* LONGTERMTODO: Old code fetches glyph classes at most once and caches /* LONGTERMTODO: Old code fetches glyph classes at most once and caches
* them across subrule lookups. Not sure it's worth it. * them across subrule lookups. Not sure it's worth it.
*/ */
// struct ContextLookupContext context = { struct ChainContextLookupContext context = {
// class_match, (char *) &(this+classDef), {match_class, apply_func},
// apply_func {(char *) &backtrack_class_def,
// }; (char *) &input_class_def,
// return rule_set.apply (LOOKUP_ARGS, context); (char *) &lookahead_class_def}
return false; };
return rule_set.apply (LOOKUP_ARGS, context);
} }
private: private:
USHORT format; /* Format identifier--format = 2 */ USHORT format; /* Format identifier--format = 2 */
Offset coverage; /* Offset to Coverage table--from OffsetTo<Coverage>
coverage; /* Offset to Coverage table--from
* beginning of table */ * beginning of table */
Offset backtrackClassDef; /* Offset to glyph ClassDef table OffsetTo<ClassDef>
backtrackClassDef; /* Offset to glyph ClassDef table
* containing backtrack sequence * containing backtrack sequence
* data--from beginning of table */ * data--from beginning of table */
Offset inputClassDef; /* Offset to glyph ClassDef OffsetTo<ClassDef>
inputClassDef; /* Offset to glyph ClassDef
* table containing input sequence * table containing input sequence
* data--from beginning of table */ * data--from beginning of table */
Offset lookaheadClassDef; /* Offset to glyph ClassDef table OffsetTo<ClassDef>
lookaheadClassDef; /* Offset to glyph ClassDef table
* containing lookahead sequence * containing lookahead sequence
* data--from beginning of table */ * data--from beginning of table */
USHORT chainClassSetCnt; /* Number of ChainClassSet tables */ OffsetArrayOf<ChainRuleSet>
Offset chainClassSet[]; /* Array of offsets to ChainClassSet ruleSet; /* Array of ChainRuleSet tables
* tables--from beginning of * ordered by class */
* table--ordered by input
* class--may be NULL */
}; };
ASSERT_SIZE (ChainContextFormat2, 12); ASSERT_SIZE (ChainContextFormat2, 12);
...@@ -465,13 +486,32 @@ struct ChainContextFormat3 { ...@@ -465,13 +486,32 @@ struct ChainContextFormat3 {
friend struct ChainContext; friend struct ChainContext;
private: private:
inline bool apply (LOOKUP_ARGS_DEF, apply_lookup_func_t apply_func) const {
// if ((*this)[0].get_coverage (IN_CURGLYPH () == NOT_COVERED)) inline bool apply_coverage (LOOKUP_ARGS_DEF, apply_lookup_func_t apply_func) const {
// return false; // const LookupRecord *record = (const LookupRecord *) ((const char *) coverage + sizeof (coverage[0]) * glyphCount);
struct ChainContextLookupContext context = {
{match_coverage, apply_func},
{(char *) this, (char *) this, (char *) this}
};
/*
return context_lookup (LOOKUP_ARGS,
glyphCount,
(const USHORT *) (coverage + 1),
lookupCount,
record,
context);
*/
return false;
}
// return apply_coverage (LOOKUP_ARGS, apply_func); inline bool apply (LOOKUP_ARGS_DEF, apply_lookup_func_t apply_func) const {
/* XXX */
unsigned int index = 0;//(this+coverage[0]) (IN_CURGLYPH ());
if (G_LIKELY (index == NOT_COVERED))
return false; return false;
return apply_coverage (LOOKUP_ARGS, apply_func);
} }
private: private:
...@@ -481,17 +521,17 @@ struct ChainContextFormat3 { ...@@ -481,17 +521,17 @@ struct ChainContextFormat3 {
Offset backtrackCoverage[]; /* Array of offsets to coverage tables Offset backtrackCoverage[]; /* Array of offsets to coverage tables
* in backtracking sequence, in glyph * in backtracking sequence, in glyph
* sequence order */ * sequence order */
USHORT inputGlyphCount; /* Number of glyphs in input sequence */ USHORT inputGlyphCountX; /* Number of glyphs in input sequence */
Offset inputCoverage[]; /* Array of offsets to coverage Offset inputCoverageX[]; /* Array of offsets to coverage
* tables in input sequence, in glyph * tables in input sequence, in glyph
* sequence order */ * sequence order */
USHORT lookaheadGlyphCount; /* Number of glyphs in lookahead USHORT lookaheadGlyphCountX; /* Number of glyphs in lookahead
* sequence */ * sequence */
Offset lookaheadCoverage[]; /* Array of offsets to coverage tables Offset lookaheadCoverageX[]; /* Array of offsets to coverage tables
* in lookahead sequence, in glyph * in lookahead sequence, in glyph
* sequence order */ * sequence order */
USHORT substCount; /* Number of LookupRecords */ USHORT lookupCountX; /* Number of LookupRecords */
LookupRecord substLookupRecord[]; /* Array of LookupRecords--in LookupRecord lookupRecordX[]; /* Array of LookupRecords--in
* design order */ * design order */
}; };
ASSERT_SIZE (ChainContextFormat3, 10); ASSERT_SIZE (ChainContextFormat3, 10);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册