From 8e6b6bb2932946ebc7b01c3abf575b654c741e20 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 14 May 2010 21:58:22 -0400 Subject: [PATCH] Merge buffer->out_pos and buffer->out_length --- src/hb-buffer-private.hh | 1 - src/hb-buffer.cc | 48 ++++++++++++---------------- src/hb-ot-layout-gsub-private.hh | 2 +- src/hb-ot-layout-gsubgpos-private.hh | 6 ++-- 4 files changed, 24 insertions(+), 33 deletions(-) diff --git a/src/hb-buffer-private.hh b/src/hb-buffer-private.hh index fabfbd45a..9296fb510 100644 --- a/src/hb-buffer-private.hh +++ b/src/hb-buffer-private.hh @@ -113,7 +113,6 @@ struct _hb_buffer_t { unsigned int in_length; unsigned int out_length; unsigned int in_pos; - unsigned int out_pos; /* out_length and out_pos are actually always the same */ hb_internal_glyph_info_t *in_string; hb_internal_glyph_info_t *out_string; diff --git a/src/hb-buffer.cc b/src/hb-buffer.cc index bad5dcd09..1f8f1830c 100644 --- a/src/hb-buffer.cc +++ b/src/hb-buffer.cc @@ -184,7 +184,6 @@ hb_buffer_clear (hb_buffer_t *buffer) buffer->in_length = 0; buffer->out_length = 0; buffer->in_pos = 0; - buffer->out_pos = 0; buffer->out_string = buffer->in_string; buffer->max_lig_id = 0; } @@ -247,7 +246,6 @@ _hb_buffer_clear_output (hb_buffer_t *buffer) buffer->have_output = TRUE; buffer->have_positions = FALSE; buffer->out_length = 0; - buffer->out_pos = 0; buffer->out_string = buffer->in_string; } @@ -287,9 +285,7 @@ _hb_buffer_swap (hb_buffer_t *buffer) buffer->in_length = buffer->out_length; buffer->out_length = tmp; - tmp = buffer->in_pos; - buffer->in_pos = buffer->out_pos; - buffer->out_pos = tmp; + buffer->in_pos = 0; } /* The following function copies `num_out' elements from `glyph_data' @@ -325,9 +321,9 @@ _hb_buffer_add_output_glyphs (hb_buffer_t *buffer, unsigned int cluster; if (buffer->out_string != buffer->in_string || - buffer->out_pos + num_out > buffer->in_pos + num_in) + buffer->out_length + num_out > buffer->in_pos + num_in) { - hb_buffer_ensure_separate (buffer, buffer->out_pos + num_out); + hb_buffer_ensure_separate (buffer, buffer->out_length + num_out); } mask = buffer->in_string[buffer->in_pos].mask; @@ -339,7 +335,7 @@ _hb_buffer_add_output_glyphs (hb_buffer_t *buffer, for (i = 0; i < num_out; i++) { - hb_internal_glyph_info_t *info = &buffer->out_string[buffer->out_pos + i]; + hb_internal_glyph_info_t *info = &buffer->out_string[buffer->out_length + i]; info->codepoint = glyph_data[i]; info->mask = mask; info->cluster = cluster; @@ -349,8 +345,7 @@ _hb_buffer_add_output_glyphs (hb_buffer_t *buffer, } buffer->in_pos += num_in; - buffer->out_pos += num_out; - buffer->out_length = buffer->out_pos; + buffer->out_length += num_out; } void @@ -366,9 +361,9 @@ _hb_buffer_add_output_glyphs_be16 (hb_buffer_t *buffer, unsigned int cluster; if (buffer->out_string != buffer->in_string || - buffer->out_pos + num_out > buffer->in_pos + num_in) + buffer->out_length + num_out > buffer->in_pos + num_in) { - hb_buffer_ensure_separate (buffer, buffer->out_pos + num_out); + hb_buffer_ensure_separate (buffer, buffer->out_length + num_out); } mask = buffer->in_string[buffer->in_pos].mask; @@ -380,7 +375,7 @@ _hb_buffer_add_output_glyphs_be16 (hb_buffer_t *buffer, for (i = 0; i < num_out; i++) { - hb_internal_glyph_info_t *info = &buffer->out_string[buffer->out_pos + i]; + hb_internal_glyph_info_t *info = &buffer->out_string[buffer->out_length + i]; info->codepoint = hb_be_uint16 (glyph_data_be[i]); info->mask = mask; info->cluster = cluster; @@ -390,8 +385,7 @@ _hb_buffer_add_output_glyphs_be16 (hb_buffer_t *buffer, } buffer->in_pos += num_in; - buffer->out_pos += num_out; - buffer->out_length = buffer->out_pos; + buffer->out_length += num_out; } void @@ -404,13 +398,13 @@ _hb_buffer_add_output_glyph (hb_buffer_t *buffer, if (buffer->out_string != buffer->in_string) { - hb_buffer_ensure (buffer, buffer->out_pos + 1); - buffer->out_string[buffer->out_pos] = buffer->in_string[buffer->in_pos]; + hb_buffer_ensure (buffer, buffer->out_length + 1); + buffer->out_string[buffer->out_length] = buffer->in_string[buffer->in_pos]; } - else if (buffer->out_pos != buffer->in_pos) - buffer->out_string[buffer->out_pos] = buffer->in_string[buffer->in_pos]; + else if (buffer->out_length != buffer->in_pos) + buffer->out_string[buffer->out_length] = buffer->in_string[buffer->in_pos]; - info = &buffer->out_string[buffer->out_pos]; + info = &buffer->out_string[buffer->out_length]; info->codepoint = glyph_index; if (component != 0xFFFF) info->component = component; @@ -419,8 +413,7 @@ _hb_buffer_add_output_glyph (hb_buffer_t *buffer, info->gproperty = HB_BUFFER_GLYPH_PROPERTIES_UNKNOWN; buffer->in_pos++; - buffer->out_pos++; - buffer->out_length = buffer->out_pos; + buffer->out_length++; } void @@ -430,14 +423,13 @@ _hb_buffer_next_glyph (hb_buffer_t *buffer) { if (buffer->out_string != buffer->in_string) { - hb_buffer_ensure (buffer, buffer->out_pos + 1); - buffer->out_string[buffer->out_pos] = buffer->in_string[buffer->in_pos]; + hb_buffer_ensure (buffer, buffer->out_length + 1); + buffer->out_string[buffer->out_length] = buffer->in_string[buffer->in_pos]; } - else if (buffer->out_pos != buffer->in_pos) - buffer->out_string[buffer->out_pos] = buffer->in_string[buffer->in_pos]; + else if (buffer->out_length != buffer->in_pos) + buffer->out_string[buffer->out_length] = buffer->in_string[buffer->in_pos]; - buffer->out_pos++; - buffer->out_length = buffer->out_pos; + buffer->out_length++; } buffer->in_pos++; diff --git a/src/hb-ot-layout-gsub-private.hh b/src/hb-ot-layout-gsub-private.hh index 59c498e01..965d19908 100644 --- a/src/hb-ot-layout-gsub-private.hh +++ b/src/hb-ot-layout-gsub-private.hh @@ -289,7 +289,7 @@ struct AlternateSubstFormat1 /* XXX callback to user to choose alternate if (c->layout->face->altfunc) alt_index = (c->layout->face->altfunc)(c->layout->layout, c->buffer, - c->buffer->out_pos, glyph_id, + c->buffer->out_length, glyph_id, alt_set.len, alt_set.array); */ diff --git a/src/hb-ot-layout-gsubgpos-private.hh b/src/hb-ot-layout-gsubgpos-private.hh index f11080ebb..5c2279713 100644 --- a/src/hb-ot-layout-gsubgpos-private.hh +++ b/src/hb-ot-layout-gsubgpos-private.hh @@ -116,10 +116,10 @@ static inline bool match_backtrack (hb_apply_context_t *c, match_func_t match_func, const void *match_data) { - if (unlikely (c->buffer->out_pos < count)) + if (unlikely (c->buffer->out_length < count)) return false; - for (unsigned int i = 0, j = c->buffer->out_pos - 1; i < count; i++, j--) + for (unsigned int i = 0, j = c->buffer->out_length - 1; i < count; i++, j--) { while (_hb_ot_layout_skip_mark (c->layout->face, &c->buffer->out_string[j], c->lookup_flag, NULL)) { @@ -519,7 +519,7 @@ static inline bool chain_context_lookup (hb_apply_context_t *c, ChainContextLookupContext &lookup_context) { /* First guess */ - if (unlikely (c->buffer->out_pos < backtrackCount || + if (unlikely (c->buffer->out_length < backtrackCount || c->buffer->in_pos + inputCount + lookaheadCount > c->buffer->in_length || inputCount + lookaheadCount > c->context_length)) return false;