mirror of
https://github.com/harfbuzz/harfbuzz.git
synced 2025-04-13 08:42:59 +00:00
[Coverage/ClassDef] Don't call qsort if sorted already
This commit is contained in:
parent
3c2a925b7f
commit
4ad443d5ea
2 changed files with 15 additions and 2 deletions
|
@ -95,10 +95,14 @@ struct CoverageFormat2_4
|
|||
unsigned count = 0;
|
||||
unsigned range = (unsigned) -1;
|
||||
last = (hb_codepoint_t) -2;
|
||||
unsigned unsorted = false;
|
||||
for (auto g: glyphs)
|
||||
{
|
||||
if (last + 1 != g)
|
||||
{
|
||||
if (unlikely (last != (hb_codepoint_t) -2 && last + 1 > g))
|
||||
unsorted = true;
|
||||
|
||||
range++;
|
||||
rangeRecord.arrayZ[range].first = g;
|
||||
rangeRecord.arrayZ[range].value = count;
|
||||
|
@ -107,7 +111,9 @@ struct CoverageFormat2_4
|
|||
last = g;
|
||||
count++;
|
||||
}
|
||||
rangeRecord.as_array ().qsort (RangeRecord<Types>::cmp_range); // To handle unsorted glyph order.
|
||||
|
||||
if (unlikely (unsorted))
|
||||
rangeRecord.as_array ().qsort (RangeRecord<Types>::cmp_range);
|
||||
|
||||
return_trace (true);
|
||||
}
|
||||
|
|
|
@ -1769,6 +1769,7 @@ struct ClassDefFormat2_4
|
|||
return_trace (true);
|
||||
}
|
||||
|
||||
unsigned unsorted = false;
|
||||
unsigned num_ranges = 1;
|
||||
hb_codepoint_t prev_gid = (*it).first;
|
||||
unsigned prev_klass = (*it).second;
|
||||
|
@ -1789,6 +1790,10 @@ struct ClassDefFormat2_4
|
|||
if (cur_gid != prev_gid + 1 ||
|
||||
cur_klass != prev_klass)
|
||||
{
|
||||
|
||||
if (unlikely (cur_gid < prev_gid))
|
||||
unsorted = true;
|
||||
|
||||
if (unlikely (!record)) break;
|
||||
record->last = prev_gid;
|
||||
num_ranges++;
|
||||
|
@ -1808,7 +1813,9 @@ struct ClassDefFormat2_4
|
|||
|
||||
if (likely (record)) record->last = prev_gid;
|
||||
rangeRecord.len = num_ranges;
|
||||
rangeRecord.as_array ().qsort (RangeRecord<Types>::cmp_range); // To handle unsorted glyph order.
|
||||
|
||||
if (unlikely (unsorted))
|
||||
rangeRecord.as_array ().qsort (RangeRecord<Types>::cmp_range);
|
||||
|
||||
return_trace (true);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue