[buffer] HB_NODISCARD next_glyph()

This commit is contained in:
Behdad Esfahbod 2021-03-15 15:18:06 -06:00
parent f4bc7673db
commit 8450f43ae1
10 changed files with 57 additions and 55 deletions

View File

@ -101,7 +101,7 @@ class ConstraintSet (object):
self._indent (depth + 2), cp, index + i, ')' if i == len (self._c) - 1 else ' &&')) self._indent (depth + 2), cp, index + i, ')' if i == len (self._c) - 1 else ' &&'))
s.append ('{}{{\n'.format (indent)) s.append ('{}{{\n'.format (indent))
for i in range (index): for i in range (index):
s.append ('{}buffer->next_glyph ();\n'.format (self._indent (depth + 1))) s.append ('{}(void) buffer->next_glyph ();\n'.format (self._indent (depth + 1)))
s.append ('{}matched = true;\n'.format (self._indent (depth + 1))) s.append ('{}matched = true;\n'.format (self._indent (depth + 1)))
s.append ('{}}}\n'.format (indent)) s.append ('{}}}\n'.format (indent))
else: else:
@ -179,7 +179,7 @@ print ('static void')
print ('_output_with_dotted_circle (hb_buffer_t *buffer)') print ('_output_with_dotted_circle (hb_buffer_t *buffer)')
print ('{') print ('{')
print (' _output_dotted_circle (buffer);') print (' _output_dotted_circle (buffer);')
print (' buffer->next_glyph ();') print (' (void) buffer->next_glyph ();')
print ('}') print ('}')
print () print ()
@ -211,7 +211,7 @@ for script, constraints in sorted (constraints.items (), key=lambda s_c: script_
print (' {') print (' {')
print ('\tbool matched = false;') print ('\tbool matched = false;')
write (str (constraints)) write (str (constraints))
print ('\tbuffer->next_glyph ();') print ('\t(void) buffer->next_glyph ();')
print ('\tif (matched) _output_with_dotted_circle (buffer);') print ('\tif (matched) _output_with_dotted_circle (buffer);')
print (' }') print (' }')
print (' break;') print (' break;')

View File

@ -831,7 +831,7 @@ struct StateTableDriver
break; break;
if (!(entry.flags & context_t::DontAdvance) || buffer->max_ops-- <= 0) if (!(entry.flags & context_t::DontAdvance) || buffer->max_ops-- <= 0)
buffer->next_glyph (); (void) buffer->next_glyph ();
} }
if (!c->in_place) if (!c->in_place)

View File

@ -262,7 +262,7 @@ struct hb_buffer_t
/* Copies glyph at idx to output and advance idx. /* Copies glyph at idx to output and advance idx.
* If there's no output, just advance idx. */ * If there's no output, just advance idx. */
bool next_glyph () HB_NODISCARD bool next_glyph ()
{ {
if (have_output) if (have_output)
{ {

View File

@ -1043,7 +1043,7 @@ static inline bool ligate_input (hb_ot_apply_context_t *c,
hb_min (this_comp, last_num_components); hb_min (this_comp, last_num_components);
_hb_glyph_info_set_lig_props_for_mark (&buffer->cur(), lig_id, new_lig_comp); _hb_glyph_info_set_lig_props_for_mark (&buffer->cur(), lig_id, new_lig_comp);
} }
buffer->next_glyph (); (void) buffer->next_glyph ();
} }
last_lig_id = _hb_glyph_info_get_lig_id (&buffer->cur()); last_lig_id = _hb_glyph_info_get_lig_id (&buffer->cur());

View File

@ -1782,7 +1782,7 @@ apply_forward (OT::hb_ot_apply_context_t *c,
if (applied) if (applied)
ret = true; ret = true;
else else
buffer->next_glyph (); (void) buffer->next_glyph ();
} }
return ret; return ret;
} }

View File

@ -205,7 +205,7 @@ preprocess_text_hangul (const hb_ot_shape_plan_t *plan HB_UNUSED,
{ {
/* Tone mark follows a valid syllable; move it in front, unless it's zero width. */ /* Tone mark follows a valid syllable; move it in front, unless it's zero width. */
buffer->unsafe_to_break_from_outbuffer (start, buffer->idx); buffer->unsafe_to_break_from_outbuffer (start, buffer->idx);
buffer->next_glyph (); if (unlikely (!buffer->next_glyph ())) break;
if (!is_zero_width_char (font, u)) if (!is_zero_width_char (font, u))
{ {
buffer->merge_out_clusters (start, end + 1); buffer->merge_out_clusters (start, end + 1);
@ -236,7 +236,7 @@ preprocess_text_hangul (const hb_ot_shape_plan_t *plan HB_UNUSED,
else else
{ {
/* No dotted circle available in the font; just leave tone mark untouched. */ /* No dotted circle available in the font; just leave tone mark untouched. */
buffer->next_glyph (); (void) buffer->next_glyph ();
} }
} }
start = end = buffer->out_len; start = end = buffer->out_len;
@ -285,13 +285,13 @@ preprocess_text_hangul (const hb_ot_shape_plan_t *plan HB_UNUSED,
* Set jamo features on the individual glyphs, and advance past them. * Set jamo features on the individual glyphs, and advance past them.
*/ */
buffer->cur().hangul_shaping_feature() = LJMO; buffer->cur().hangul_shaping_feature() = LJMO;
buffer->next_glyph (); (void) buffer->next_glyph ();
buffer->cur().hangul_shaping_feature() = VJMO; buffer->cur().hangul_shaping_feature() = VJMO;
buffer->next_glyph (); (void) buffer->next_glyph ();
if (t) if (t)
{ {
buffer->cur().hangul_shaping_feature() = TJMO; buffer->cur().hangul_shaping_feature() = TJMO;
buffer->next_glyph (); (void) buffer->next_glyph ();
end = start + 3; end = start + 3;
} }
else else
@ -354,7 +354,7 @@ preprocess_text_hangul (const hb_ot_shape_plan_t *plan HB_UNUSED,
*/ */
if (has_glyph && !tindex) if (has_glyph && !tindex)
{ {
buffer->next_glyph (); (void) buffer->next_glyph ();
s_len++; s_len++;
} }
if (unlikely (!buffer->successful)) if (unlikely (!buffer->successful))
@ -382,17 +382,15 @@ preprocess_text_hangul (const hb_ot_shape_plan_t *plan HB_UNUSED,
if (has_glyph) if (has_glyph)
{ {
/* We didn't decompose the S, so just advance past it. */ /* We didn't decompose the S, so just advance past it and fall through. */
end = start + 1; end = start + 1;
buffer->next_glyph ();
continue;
} }
} }
/* Didn't find a recognizable syllable, so we leave end <= start; /* Didn't find a recognizable syllable, so we leave end <= start;
* this will prevent tone-mark reordering happening. * this will prevent tone-mark reordering happening.
*/ */
buffer->next_glyph (); (void) buffer->next_glyph ();
} }
buffer->swap_buffers (); buffer->swap_buffers ();
} }

View File

@ -85,13 +85,13 @@ hb_syllabic_insert_dotted_circles (hb_font_t *font,
while (buffer->idx < buffer->len && buffer->successful && while (buffer->idx < buffer->len && buffer->successful &&
last_syllable == buffer->cur().syllable() && last_syllable == buffer->cur().syllable() &&
buffer->cur().complex_var_u8_category() == (unsigned) repha_category) buffer->cur().complex_var_u8_category() == (unsigned) repha_category)
buffer->next_glyph (); (void) buffer->next_glyph ();
} }
(void) buffer->output_info (ginfo); (void) buffer->output_info (ginfo);
} }
else else
buffer->next_glyph (); (void) buffer->next_glyph ();
} }
buffer->swap_buffers (); buffer->swap_buffers ();
} }

View File

@ -323,16 +323,17 @@ preprocess_text_thai (const hb_ot_shape_plan_t *plan,
buffer->clear_output (); buffer->clear_output ();
unsigned int count = buffer->len; unsigned int count = buffer->len;
for (buffer->idx = 0; buffer->idx < count && buffer->successful;) for (buffer->idx = 0; buffer->idx < count /* No need for: && buffer->successful */;)
{ {
hb_codepoint_t u = buffer->cur().codepoint; hb_codepoint_t u = buffer->cur().codepoint;
if (likely (!IS_SARA_AM (u))) { if (likely (!IS_SARA_AM (u)))
buffer->next_glyph (); {
if (unlikely (!buffer->next_glyph ())) break;
continue; continue;
} }
/* Is SARA AM. Decompose and reorder. */ /* Is SARA AM. Decompose and reorder. */
if (unlikely (!buffer->output_glyph (NIKHAHIT_FROM_SARA_AM (u)))) break; (void) buffer->output_glyph (NIKHAHIT_FROM_SARA_AM (u));
_hb_glyph_info_set_continuation (&buffer->prev()); _hb_glyph_info_set_continuation (&buffer->prev());
if (unlikely (!buffer->replace_glyph (SARA_AA_FROM_SARA_AM (u)))) break; if (unlikely (!buffer->replace_glyph (SARA_AA_FROM_SARA_AM (u)))) break;

View File

@ -31,7 +31,7 @@ static void
_output_with_dotted_circle (hb_buffer_t *buffer) _output_with_dotted_circle (hb_buffer_t *buffer)
{ {
_output_dotted_circle (buffer); _output_dotted_circle (buffer);
buffer->next_glyph (); (void) buffer->next_glyph ();
} }
void void
@ -96,12 +96,12 @@ _hb_preprocess_text_vowel_constraints (const hb_ot_shape_plan_t *plan HB_UNUSED,
buffer->idx + 2 < count && buffer->idx + 2 < count &&
0x0907u == buffer->cur (2).codepoint) 0x0907u == buffer->cur (2).codepoint)
{ {
buffer->next_glyph (); (void) buffer->next_glyph ();
matched = true; matched = true;
} }
break; break;
} }
buffer->next_glyph (); (void) buffer->next_glyph ();
if (matched) _output_with_dotted_circle (buffer); if (matched) _output_with_dotted_circle (buffer);
} }
break; break;
@ -122,7 +122,7 @@ _hb_preprocess_text_vowel_constraints (const hb_ot_shape_plan_t *plan HB_UNUSED,
matched = 0x09E2u == buffer->cur (1).codepoint; matched = 0x09E2u == buffer->cur (1).codepoint;
break; break;
} }
buffer->next_glyph (); (void) buffer->next_glyph ();
if (matched) _output_with_dotted_circle (buffer); if (matched) _output_with_dotted_circle (buffer);
} }
break; break;
@ -158,7 +158,7 @@ _hb_preprocess_text_vowel_constraints (const hb_ot_shape_plan_t *plan HB_UNUSED,
} }
break; break;
} }
buffer->next_glyph (); (void) buffer->next_glyph ();
if (matched) _output_with_dotted_circle (buffer); if (matched) _output_with_dotted_circle (buffer);
} }
break; break;
@ -182,7 +182,7 @@ _hb_preprocess_text_vowel_constraints (const hb_ot_shape_plan_t *plan HB_UNUSED,
matched = 0x0ABEu == buffer->cur (1).codepoint; matched = 0x0ABEu == buffer->cur (1).codepoint;
break; break;
} }
buffer->next_glyph (); (void) buffer->next_glyph ();
if (matched) _output_with_dotted_circle (buffer); if (matched) _output_with_dotted_circle (buffer);
} }
break; break;
@ -200,7 +200,7 @@ _hb_preprocess_text_vowel_constraints (const hb_ot_shape_plan_t *plan HB_UNUSED,
matched = 0x0B57u == buffer->cur (1).codepoint; matched = 0x0B57u == buffer->cur (1).codepoint;
break; break;
} }
buffer->next_glyph (); (void) buffer->next_glyph ();
if (matched) _output_with_dotted_circle (buffer); if (matched) _output_with_dotted_circle (buffer);
} }
break; break;
@ -214,7 +214,7 @@ _hb_preprocess_text_vowel_constraints (const hb_ot_shape_plan_t *plan HB_UNUSED,
{ {
matched = true; matched = true;
} }
buffer->next_glyph (); (void) buffer->next_glyph ();
if (matched) _output_with_dotted_circle (buffer); if (matched) _output_with_dotted_circle (buffer);
} }
break; break;
@ -237,7 +237,7 @@ _hb_preprocess_text_vowel_constraints (const hb_ot_shape_plan_t *plan HB_UNUSED,
matched = 0x0C55u == buffer->cur (1).codepoint; matched = 0x0C55u == buffer->cur (1).codepoint;
break; break;
} }
buffer->next_glyph (); (void) buffer->next_glyph ();
if (matched) _output_with_dotted_circle (buffer); if (matched) _output_with_dotted_circle (buffer);
} }
break; break;
@ -255,7 +255,7 @@ _hb_preprocess_text_vowel_constraints (const hb_ot_shape_plan_t *plan HB_UNUSED,
matched = 0x0CCCu == buffer->cur (1).codepoint; matched = 0x0CCCu == buffer->cur (1).codepoint;
break; break;
} }
buffer->next_glyph (); (void) buffer->next_glyph ();
if (matched) _output_with_dotted_circle (buffer); if (matched) _output_with_dotted_circle (buffer);
} }
break; break;
@ -281,7 +281,7 @@ _hb_preprocess_text_vowel_constraints (const hb_ot_shape_plan_t *plan HB_UNUSED,
} }
break; break;
} }
buffer->next_glyph (); (void) buffer->next_glyph ();
if (matched) _output_with_dotted_circle (buffer); if (matched) _output_with_dotted_circle (buffer);
} }
break; break;
@ -316,7 +316,7 @@ _hb_preprocess_text_vowel_constraints (const hb_ot_shape_plan_t *plan HB_UNUSED,
} }
break; break;
} }
buffer->next_glyph (); (void) buffer->next_glyph ();
if (matched) _output_with_dotted_circle (buffer); if (matched) _output_with_dotted_circle (buffer);
} }
break; break;
@ -337,7 +337,7 @@ _hb_preprocess_text_vowel_constraints (const hb_ot_shape_plan_t *plan HB_UNUSED,
matched = 0x11042u == buffer->cur (1).codepoint; matched = 0x11042u == buffer->cur (1).codepoint;
break; break;
} }
buffer->next_glyph (); (void) buffer->next_glyph ();
if (matched) _output_with_dotted_circle (buffer); if (matched) _output_with_dotted_circle (buffer);
} }
break; break;
@ -358,7 +358,7 @@ _hb_preprocess_text_vowel_constraints (const hb_ot_shape_plan_t *plan HB_UNUSED,
} }
break; break;
} }
buffer->next_glyph (); (void) buffer->next_glyph ();
if (matched) _output_with_dotted_circle (buffer); if (matched) _output_with_dotted_circle (buffer);
} }
break; break;
@ -384,7 +384,7 @@ _hb_preprocess_text_vowel_constraints (const hb_ot_shape_plan_t *plan HB_UNUSED,
} }
break; break;
} }
buffer->next_glyph (); (void) buffer->next_glyph ();
if (matched) _output_with_dotted_circle (buffer); if (matched) _output_with_dotted_circle (buffer);
} }
break; break;
@ -404,7 +404,7 @@ _hb_preprocess_text_vowel_constraints (const hb_ot_shape_plan_t *plan HB_UNUSED,
} }
break; break;
} }
buffer->next_glyph (); (void) buffer->next_glyph ();
if (matched) _output_with_dotted_circle (buffer); if (matched) _output_with_dotted_circle (buffer);
} }
break; break;
@ -427,7 +427,7 @@ _hb_preprocess_text_vowel_constraints (const hb_ot_shape_plan_t *plan HB_UNUSED,
matched = 0x116B2u == buffer->cur (1).codepoint; matched = 0x116B2u == buffer->cur (1).codepoint;
break; break;
} }
buffer->next_glyph (); (void) buffer->next_glyph ();
if (matched) _output_with_dotted_circle (buffer); if (matched) _output_with_dotted_circle (buffer);
} }
break; break;

View File

@ -111,7 +111,7 @@ static inline void
next_char (hb_buffer_t *buffer, hb_codepoint_t glyph) next_char (hb_buffer_t *buffer, hb_codepoint_t glyph)
{ {
buffer->cur().glyph_index() = glyph; buffer->cur().glyph_index() = glyph;
buffer->next_glyph (); (void) buffer->next_glyph ();
} }
static inline void static inline void
@ -236,24 +236,29 @@ handle_variation_selector_cluster (const hb_ot_shape_normalize_context_t *c,
{ {
/* Just pass on the two characters separately, let GSUB do its magic. */ /* Just pass on the two characters separately, let GSUB do its magic. */
set_glyph (buffer->cur(), font); set_glyph (buffer->cur(), font);
buffer->next_glyph (); (void) buffer->next_glyph ();
set_glyph (buffer->cur(), font); set_glyph (buffer->cur(), font);
buffer->next_glyph (); (void) buffer->next_glyph ();
} }
/* Skip any further variation selectors. */ /* Skip any further variation selectors. */
while (buffer->idx < end && unlikely (buffer->unicode->is_variation_selector (buffer->cur().codepoint))) while (buffer->idx < end &&
buffer->successful &&
unlikely (buffer->unicode->is_variation_selector (buffer->cur().codepoint)))
{ {
set_glyph (buffer->cur(), font); set_glyph (buffer->cur(), font);
buffer->next_glyph (); (void) buffer->next_glyph ();
} }
} else { }
else
{
set_glyph (buffer->cur(), font); set_glyph (buffer->cur(), font);
buffer->next_glyph (); (void) buffer->next_glyph ();
} }
} }
if (likely (buffer->idx < end)) { if (likely (buffer->idx < end))
{
set_glyph (buffer->cur(), font); set_glyph (buffer->cur(), font);
buffer->next_glyph (); (void) buffer->next_glyph ();
} }
} }
@ -430,8 +435,8 @@ _hb_ot_shape_normalize (const hb_ot_shape_plan_t *plan,
buffer->clear_output (); buffer->clear_output ();
count = buffer->len; count = buffer->len;
unsigned int starter = 0; unsigned int starter = 0;
buffer->next_glyph (); (void) buffer->next_glyph ();
while (buffer->idx < count && buffer->successful) while (buffer->idx < count /* No need for: && buffer->successful */)
{ {
hb_codepoint_t composed, glyph; hb_codepoint_t composed, glyph;
if (/* We don't try to compose a non-mark character with it's preceding starter. if (/* We don't try to compose a non-mark character with it's preceding starter.
@ -453,9 +458,7 @@ _hb_ot_shape_normalize (const hb_ot_shape_plan_t *plan,
font->get_nominal_glyph (composed, &glyph)) font->get_nominal_glyph (composed, &glyph))
{ {
/* Composes. */ /* Composes. */
buffer->next_glyph (); /* Copy to out-buffer. */ if (unlikely (!buffer->next_glyph ())) break; /* Copy to out-buffer. */
if (unlikely (!buffer->successful))
return;
buffer->merge_out_clusters (starter, buffer->out_len); buffer->merge_out_clusters (starter, buffer->out_len);
buffer->out_len--; /* Remove the second composable. */ buffer->out_len--; /* Remove the second composable. */
/* Modify starter and carry on. */ /* Modify starter and carry on. */
@ -468,7 +471,7 @@ _hb_ot_shape_normalize (const hb_ot_shape_plan_t *plan,
} }
/* Blocked, or doesn't compose. */ /* Blocked, or doesn't compose. */
buffer->next_glyph (); if (unlikely (!buffer->next_glyph ())) break;
if (info_cc (buffer->prev()) == 0) if (info_cc (buffer->prev()) == 0)
starter = buffer->out_len - 1; starter = buffer->out_len - 1;