Move context_length into apply_context

This commit is contained in:
Behdad Esfahbod 2010-05-05 01:23:44 -04:00
parent 94a23aaeca
commit 969c9705ae
3 changed files with 50 additions and 38 deletions

View File

@ -577,7 +577,7 @@ struct PairPosFormat1
inline bool apply (APPLY_ARG_DEF) const inline bool apply (APPLY_ARG_DEF) const
{ {
TRACE_APPLY (); TRACE_APPLY ();
unsigned int end = MIN (context->buffer->in_length, context->buffer->in_pos + context_length); unsigned int end = MIN (context->buffer->in_length, context->buffer->in_pos + context->context_length);
if (unlikely (context->buffer->in_pos + 2 > end)) if (unlikely (context->buffer->in_pos + 2 > end))
return false; return false;
@ -670,7 +670,7 @@ struct PairPosFormat2
inline bool apply (APPLY_ARG_DEF) const inline bool apply (APPLY_ARG_DEF) const
{ {
TRACE_APPLY (); TRACE_APPLY ();
unsigned int end = MIN (context->buffer->in_length, context->buffer->in_pos + context_length); unsigned int end = MIN (context->buffer->in_length, context->buffer->in_pos + context->context_length);
if (unlikely (context->buffer->in_pos + 2 > end)) if (unlikely (context->buffer->in_pos + 2 > end))
return false; return false;
@ -1495,6 +1495,7 @@ struct PosLookup : Lookup
context->layout = layout; context->layout = layout;
context->buffer = buffer; context->buffer = buffer;
context->context_length = context_length;
context->nesting_level_left = nesting_level_left; context->nesting_level_left = nesting_level_left;
context->lookup_flag = get_flag (); context->lookup_flag = get_flag ();
@ -1608,10 +1609,10 @@ static inline bool position_lookup (APPLY_ARG_DEF, unsigned int lookup_index)
if (unlikely (context->nesting_level_left == 0)) if (unlikely (context->nesting_level_left == 0))
return false; return false;
if (unlikely (context_length < 1)) if (unlikely (context->context_length < 1))
return false; return false;
return l.apply_once (context->layout, context->buffer, context_length, context->nesting_level_left - 1, apply_depth + 1); return l.apply_once (context->layout, context->buffer, context->context_length, context->nesting_level_left - 1, apply_depth + 1);
} }

View File

@ -367,7 +367,7 @@ struct Ligature
TRACE_APPLY (); TRACE_APPLY ();
unsigned int i, j; unsigned int i, j;
unsigned int count = component.len; unsigned int count = component.len;
unsigned int end = MIN (context->buffer->in_length, context->buffer->in_pos + context_length); unsigned int end = MIN (context->buffer->in_length, context->buffer->in_pos + context->context_length);
if (unlikely (context->buffer->in_pos + count > end)) if (unlikely (context->buffer->in_pos + count > end))
return false; return false;
@ -597,7 +597,7 @@ struct ReverseChainSingleSubstFormat1
inline bool apply (APPLY_ARG_DEF) const inline bool apply (APPLY_ARG_DEF) const
{ {
TRACE_APPLY (); TRACE_APPLY ();
if (unlikely (context_length != NO_CONTEXT)) if (unlikely (context->context_length != NO_CONTEXT))
return false; /* No chaining to this type */ return false; /* No chaining to this type */
unsigned int index = (this+coverage) (IN_CURGLYPH ()); unsigned int index = (this+coverage) (IN_CURGLYPH ());
@ -780,6 +780,7 @@ struct SubstLookup : Lookup
context->layout = layout; context->layout = layout;
context->buffer = buffer; context->buffer = buffer;
context->context_length = context_length;
context->nesting_level_left = nesting_level_left; context->nesting_level_left = nesting_level_left;
context->lookup_flag = get_flag (); context->lookup_flag = get_flag ();
@ -927,10 +928,10 @@ static inline bool substitute_lookup (APPLY_ARG_DEF, unsigned int lookup_index)
if (unlikely (context->nesting_level_left == 0)) if (unlikely (context->nesting_level_left == 0))
return false; return false;
if (unlikely (context_length < 1)) if (unlikely (context->context_length < 1))
return false; return false;
return l.apply_once (context->layout, context->buffer, context_length, context->nesting_level_left - 1, apply_depth + 1); return l.apply_once (context->layout, context->buffer, context->context_length, context->nesting_level_left - 1, apply_depth + 1);
} }

View File

@ -44,17 +44,16 @@
#define APPLY_ARG_DEF \ #define APPLY_ARG_DEF \
hb_apply_context_t *context, \ hb_apply_context_t *context, \
unsigned int context_length HB_UNUSED, \
unsigned int apply_depth HB_UNUSED unsigned int apply_depth HB_UNUSED
#define APPLY_ARG \ #define APPLY_ARG \
context, \ context, \
context_length, \
(HB_DEBUG_APPLY ? apply_depth + 1 : 0) (HB_DEBUG_APPLY ? apply_depth + 1 : 0)
struct hb_apply_context_t struct hb_apply_context_t
{ {
hb_ot_layout_context_t *layout; hb_ot_layout_context_t *layout;
hb_buffer_t *buffer; hb_buffer_t *buffer;
unsigned int context_length;
unsigned int nesting_level_left; unsigned int nesting_level_left;
unsigned int lookup_flag; unsigned int lookup_flag;
unsigned int property; /* propety of first glyph (TODO remove) */ unsigned int property; /* propety of first glyph (TODO remove) */
@ -103,7 +102,7 @@ static inline bool match_input (APPLY_ARG_DEF,
unsigned int *context_length_out) unsigned int *context_length_out)
{ {
unsigned int i, j; unsigned int i, j;
unsigned int end = MIN (context->buffer->in_length, context->buffer->in_pos + context_length); unsigned int end = MIN (context->buffer->in_length, context->buffer->in_pos + context->context_length);
if (unlikely (context->buffer->in_pos + count > end)) if (unlikely (context->buffer->in_pos + count > end))
return false; return false;
@ -158,7 +157,7 @@ static inline bool match_lookahead (APPLY_ARG_DEF,
unsigned int offset) unsigned int offset)
{ {
unsigned int i, j; unsigned int i, j;
unsigned int end = MIN (context->buffer->in_length, context->buffer->in_pos + context_length); unsigned int end = MIN (context->buffer->in_length, context->buffer->in_pos + context->context_length);
if (unlikely (context->buffer->in_pos + offset + count > end)) if (unlikely (context->buffer->in_pos + offset + count > end))
return false; return false;
@ -201,7 +200,7 @@ static inline bool apply_lookup (APPLY_ARG_DEF,
const LookupRecord lookupRecord[], /* Array of LookupRecords--in design order */ const LookupRecord lookupRecord[], /* Array of LookupRecords--in design order */
apply_lookup_func_t apply_func) apply_lookup_func_t apply_func)
{ {
unsigned int end = MIN (context->buffer->in_length, context->buffer->in_pos + context_length); unsigned int end = MIN (context->buffer->in_length, context->buffer->in_pos + context->context_length);
if (unlikely (context->buffer->in_pos + count > end)) if (unlikely (context->buffer->in_pos + count > end))
return false; return false;
@ -267,14 +266,20 @@ static inline bool context_lookup (APPLY_ARG_DEF,
const LookupRecord lookupRecord[], const LookupRecord lookupRecord[],
ContextLookupContext &lookup_context) ContextLookupContext &lookup_context)
{ {
return match_input (APPLY_ARG, unsigned int new_context_length;
inputCount, input, if (!match_input (APPLY_ARG,
lookup_context.funcs.match, lookup_context.match_data, inputCount, input,
&context_length) && lookup_context.funcs.match, lookup_context.match_data,
apply_lookup (APPLY_ARG, &new_context_length)) return false;
inputCount, unsigned int old_context_length;
lookupCount, lookupRecord, old_context_length = context->context_length;
lookup_context.funcs.apply); context->context_length = new_context_length;
bool ret = apply_lookup (APPLY_ARG,
inputCount,
lookupCount, lookupRecord,
lookup_context.funcs.apply);
context->context_length = old_context_length;
return ret;
} }
struct Rule struct Rule
@ -529,26 +534,31 @@ static inline bool chain_context_lookup (APPLY_ARG_DEF,
/* First guess */ /* First guess */
if (unlikely (context->buffer->out_pos < backtrackCount || if (unlikely (context->buffer->out_pos < backtrackCount ||
context->buffer->in_pos + inputCount + lookaheadCount > context->buffer->in_length || context->buffer->in_pos + inputCount + lookaheadCount > context->buffer->in_length ||
inputCount + lookaheadCount > context_length)) inputCount + lookaheadCount > context->context_length))
return false; return false;
unsigned int offset; unsigned int offset;
return match_backtrack (APPLY_ARG, if (!(match_backtrack (APPLY_ARG,
backtrackCount, backtrack, backtrackCount, backtrack,
lookup_context.funcs.match, lookup_context.match_data[0]) && lookup_context.funcs.match, lookup_context.match_data[0]) &&
match_input (APPLY_ARG, match_input (APPLY_ARG,
inputCount, input, inputCount, input,
lookup_context.funcs.match, lookup_context.match_data[1], lookup_context.funcs.match, lookup_context.match_data[1],
&offset) && &offset) &&
match_lookahead (APPLY_ARG, match_lookahead (APPLY_ARG,
lookaheadCount, lookahead, lookaheadCount, lookahead,
lookup_context.funcs.match, lookup_context.match_data[2], lookup_context.funcs.match, lookup_context.match_data[2],
offset) && offset))) return false;
(context_length = offset, true) &&
apply_lookup (APPLY_ARG, unsigned int old_context_length;
inputCount, old_context_length = context->context_length;
lookupCount, lookupRecord, context->context_length = offset;
lookup_context.funcs.apply); bool ret = apply_lookup (APPLY_ARG,
inputCount,
lookupCount, lookupRecord,
lookup_context.funcs.apply);
context->context_length = old_context_length;
return ret;
} }
struct ChainRule struct ChainRule