Avoid sort and recompose stages if all clusters simple
Even has measurable speedup...
This commit is contained in:
parent
9f79365c3b
commit
30c114ffec
|
@ -319,6 +319,7 @@ _hb_ot_shape_normalize (const hb_ot_shape_plan_t *plan,
|
||||||
|
|
||||||
/* First round, decompose */
|
/* First round, decompose */
|
||||||
|
|
||||||
|
bool all_simple = true;
|
||||||
buffer->clear_output ();
|
buffer->clear_output ();
|
||||||
count = buffer->len;
|
count = buffer->len;
|
||||||
buffer->idx = 0;
|
buffer->idx = 0;
|
||||||
|
@ -332,49 +333,53 @@ _hb_ot_shape_normalize (const hb_ot_shape_plan_t *plan,
|
||||||
if (end < count)
|
if (end < count)
|
||||||
end--; /* Leave one base for the marks to cluster with. */
|
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)
|
while (buffer->idx < end && buffer->successful)
|
||||||
decompose_current_character (&c, might_short_circuit);
|
decompose_current_character (&c, might_short_circuit);
|
||||||
|
|
||||||
if (buffer->idx == count || !buffer->successful)
|
if (buffer->idx == count || !buffer->successful)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
all_simple = false;
|
||||||
|
|
||||||
/* Find all the marks now. */
|
/* Find all the marks now. */
|
||||||
for (end = buffer->idx + 1; end < count; end++)
|
for (end = buffer->idx + 1; end < count; end++)
|
||||||
if (!HB_UNICODE_GENERAL_CATEGORY_IS_MARK (_hb_glyph_info_get_general_category (&buffer->info[end])))
|
if (!HB_UNICODE_GENERAL_CATEGORY_IS_MARK (_hb_glyph_info_get_general_category (&buffer->info[end])))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
/* idx to end is one non-simple cluster. */
|
||||||
decompose_multi_char_cluster (&c, end, always_short_circuit);
|
decompose_multi_char_cluster (&c, end, always_short_circuit);
|
||||||
}
|
}
|
||||||
while (buffer->idx < count && buffer->successful);
|
while (buffer->idx < count && buffer->successful);
|
||||||
buffer->swap_buffers ();
|
buffer->swap_buffers ();
|
||||||
|
|
||||||
|
|
||||||
/* Second round, reorder (inplace) */
|
/* Second round, reorder (inplace) */
|
||||||
|
if (!all_simple)
|
||||||
count = buffer->len;
|
|
||||||
for (unsigned int i = 0; i < count; i++)
|
|
||||||
{
|
{
|
||||||
if (_hb_glyph_info_get_modified_combining_class (&buffer->info[i]) == 0)
|
count = buffer->len;
|
||||||
continue;
|
for (unsigned int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
if (_hb_glyph_info_get_modified_combining_class (&buffer->info[i]) == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
unsigned int end;
|
unsigned int end;
|
||||||
for (end = i + 1; end < count; end++)
|
for (end = i + 1; end < count; end++)
|
||||||
if (_hb_glyph_info_get_modified_combining_class (&buffer->info[end]) == 0)
|
if (_hb_glyph_info_get_modified_combining_class (&buffer->info[end]) == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
/* We are going to do a O(n^2). Only do this if the sequence is short. */
|
||||||
|
if (end - i > HB_OT_SHAPE_COMPLEX_MAX_COMBINING_MARKS) {
|
||||||
|
i = end;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer->sort (i, end, compare_combining_class);
|
||||||
|
|
||||||
|
if (plan->shaper->reorder_marks)
|
||||||
|
plan->shaper->reorder_marks (plan, buffer, i, end);
|
||||||
|
|
||||||
/* We are going to do a O(n^2). Only do this if the sequence is short. */
|
|
||||||
if (end - i > HB_OT_SHAPE_COMPLEX_MAX_COMBINING_MARKS) {
|
|
||||||
i = end;
|
i = end;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer->sort (i, end, compare_combining_class);
|
|
||||||
|
|
||||||
if (plan->shaper->reorder_marks)
|
|
||||||
plan->shaper->reorder_marks (plan, buffer, i, end);
|
|
||||||
|
|
||||||
i = end;
|
|
||||||
}
|
}
|
||||||
if (buffer->scratch_flags & HB_BUFFER_SCRATCH_FLAG_HAS_CGJ)
|
if (buffer->scratch_flags & HB_BUFFER_SCRATCH_FLAG_HAS_CGJ)
|
||||||
{
|
{
|
||||||
|
@ -393,8 +398,9 @@ _hb_ot_shape_normalize (const hb_ot_shape_plan_t *plan,
|
||||||
|
|
||||||
/* Third round, recompose */
|
/* Third round, recompose */
|
||||||
|
|
||||||
if (mode == HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS ||
|
if (!all_simple &&
|
||||||
mode == HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS_NO_SHORT_CIRCUIT)
|
(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
|
/* As noted in the comment earlier, we don't try to combine
|
||||||
* ccc=0 chars with their previous Starter. */
|
* ccc=0 chars with their previous Starter. */
|
||||||
|
|
Loading…
Reference in New Issue