Avoid sort and recompose stages if all clusters simple

Even has measurable speedup...
This commit is contained in:
Behdad Esfahbod 2018-10-09 14:37:08 -04:00
parent 9f79365c3b
commit 30c114ffec
1 changed files with 29 additions and 23 deletions

View File

@ -319,6 +319,7 @@ _hb_ot_shape_normalize (const hb_ot_shape_plan_t *plan,
/* First round, decompose */
bool all_simple = true;
buffer->clear_output ();
count = buffer->len;
buffer->idx = 0;
@ -332,26 +333,29 @@ _hb_ot_shape_normalize (const hb_ot_shape_plan_t *plan,
if (end < count)
end--; /* Leave one base for the marks to cluster with. */
/* From i to end are simple clusters. */
/* From idx to end are simple clusters. */
while (buffer->idx < end && buffer->successful)
decompose_current_character (&c, might_short_circuit);
if (buffer->idx == count || !buffer->successful)
break;
all_simple = false;
/* Find all the marks now. */
for (end = buffer->idx + 1; end < count; end++)
if (!HB_UNICODE_GENERAL_CATEGORY_IS_MARK (_hb_glyph_info_get_general_category (&buffer->info[end])))
break;
/* idx to end is one non-simple cluster. */
decompose_multi_char_cluster (&c, end, always_short_circuit);
}
while (buffer->idx < count && buffer->successful);
buffer->swap_buffers ();
/* Second round, reorder (inplace) */
if (!all_simple)
{
count = buffer->len;
for (unsigned int i = 0; i < count; i++)
{
@ -376,6 +380,7 @@ _hb_ot_shape_normalize (const hb_ot_shape_plan_t *plan,
i = end;
}
}
if (buffer->scratch_flags & HB_BUFFER_SCRATCH_FLAG_HAS_CGJ)
{
/* For all CGJ, check if it prevented any reordering at all.
@ -393,8 +398,9 @@ _hb_ot_shape_normalize (const hb_ot_shape_plan_t *plan,
/* Third round, recompose */
if (mode == HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS ||
mode == HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS_NO_SHORT_CIRCUIT)
if (!all_simple &&
(mode == HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS ||
mode == HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS_NO_SHORT_CIRCUIT))
{
/* As noted in the comment earlier, we don't try to combine
* ccc=0 chars with their previous Starter. */