From 8450f43ae1d1a5825bdfc1ec665cb81b05f35cc2 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 15 Mar 2021 15:18:06 -0600 Subject: [PATCH] [buffer] HB_NODISCARD next_glyph() --- src/gen-vowel-constraints.py | 6 ++-- src/hb-aat-layout-common.hh | 2 +- src/hb-buffer.hh | 2 +- src/hb-ot-layout-gsubgpos.hh | 2 +- src/hb-ot-layout.cc | 2 +- src/hb-ot-shape-complex-hangul.cc | 18 +++++------ src/hb-ot-shape-complex-syllabic.cc | 4 +-- src/hb-ot-shape-complex-thai.cc | 9 +++--- src/hb-ot-shape-complex-vowel-constraints.cc | 34 ++++++++++---------- src/hb-ot-shape-normalize.cc | 33 ++++++++++--------- 10 files changed, 57 insertions(+), 55 deletions(-) diff --git a/src/gen-vowel-constraints.py b/src/gen-vowel-constraints.py index 2e9b50bad..184ec29cf 100755 --- a/src/gen-vowel-constraints.py +++ b/src/gen-vowel-constraints.py @@ -101,7 +101,7 @@ class ConstraintSet (object): self._indent (depth + 2), cp, index + i, ')' if i == len (self._c) - 1 else ' &&')) s.append ('{}{{\n'.format (indent)) 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 ('{}}}\n'.format (indent)) else: @@ -179,7 +179,7 @@ print ('static void') print ('_output_with_dotted_circle (hb_buffer_t *buffer)') print ('{') print (' _output_dotted_circle (buffer);') -print (' buffer->next_glyph ();') +print (' (void) buffer->next_glyph ();') print ('}') print () @@ -211,7 +211,7 @@ for script, constraints in sorted (constraints.items (), key=lambda s_c: script_ print (' {') print ('\tbool matched = false;') write (str (constraints)) - print ('\tbuffer->next_glyph ();') + print ('\t(void) buffer->next_glyph ();') print ('\tif (matched) _output_with_dotted_circle (buffer);') print (' }') print (' break;') diff --git a/src/hb-aat-layout-common.hh b/src/hb-aat-layout-common.hh index d8223dc8e..98ed20d8e 100644 --- a/src/hb-aat-layout-common.hh +++ b/src/hb-aat-layout-common.hh @@ -831,7 +831,7 @@ struct StateTableDriver break; if (!(entry.flags & context_t::DontAdvance) || buffer->max_ops-- <= 0) - buffer->next_glyph (); + (void) buffer->next_glyph (); } if (!c->in_place) diff --git a/src/hb-buffer.hh b/src/hb-buffer.hh index dac2a461d..7a754175e 100644 --- a/src/hb-buffer.hh +++ b/src/hb-buffer.hh @@ -262,7 +262,7 @@ struct hb_buffer_t /* Copies glyph at idx to output and advance idx. * If there's no output, just advance idx. */ - bool next_glyph () + HB_NODISCARD bool next_glyph () { if (have_output) { diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index b93b73c04..36a95ead1 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -1043,7 +1043,7 @@ static inline bool ligate_input (hb_ot_apply_context_t *c, hb_min (this_comp, last_num_components); _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()); diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 089c7948c..89df949b2 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -1782,7 +1782,7 @@ apply_forward (OT::hb_ot_apply_context_t *c, if (applied) ret = true; else - buffer->next_glyph (); + (void) buffer->next_glyph (); } return ret; } diff --git a/src/hb-ot-shape-complex-hangul.cc b/src/hb-ot-shape-complex-hangul.cc index 2f1bf5e1a..dbedd6af0 100644 --- a/src/hb-ot-shape-complex-hangul.cc +++ b/src/hb-ot-shape-complex-hangul.cc @@ -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. */ 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)) { buffer->merge_out_clusters (start, end + 1); @@ -236,7 +236,7 @@ preprocess_text_hangul (const hb_ot_shape_plan_t *plan HB_UNUSED, else { /* No dotted circle available in the font; just leave tone mark untouched. */ - buffer->next_glyph (); + (void) buffer->next_glyph (); } } 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. */ buffer->cur().hangul_shaping_feature() = LJMO; - buffer->next_glyph (); + (void) buffer->next_glyph (); buffer->cur().hangul_shaping_feature() = VJMO; - buffer->next_glyph (); + (void) buffer->next_glyph (); if (t) { buffer->cur().hangul_shaping_feature() = TJMO; - buffer->next_glyph (); + (void) buffer->next_glyph (); end = start + 3; } else @@ -354,7 +354,7 @@ preprocess_text_hangul (const hb_ot_shape_plan_t *plan HB_UNUSED, */ if (has_glyph && !tindex) { - buffer->next_glyph (); + (void) buffer->next_glyph (); s_len++; } if (unlikely (!buffer->successful)) @@ -382,17 +382,15 @@ preprocess_text_hangul (const hb_ot_shape_plan_t *plan HB_UNUSED, 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; - buffer->next_glyph (); - continue; } } /* Didn't find a recognizable syllable, so we leave end <= start; * this will prevent tone-mark reordering happening. */ - buffer->next_glyph (); + (void) buffer->next_glyph (); } buffer->swap_buffers (); } diff --git a/src/hb-ot-shape-complex-syllabic.cc b/src/hb-ot-shape-complex-syllabic.cc index 843fed690..46509abee 100644 --- a/src/hb-ot-shape-complex-syllabic.cc +++ b/src/hb-ot-shape-complex-syllabic.cc @@ -85,13 +85,13 @@ hb_syllabic_insert_dotted_circles (hb_font_t *font, while (buffer->idx < buffer->len && buffer->successful && last_syllable == buffer->cur().syllable() && buffer->cur().complex_var_u8_category() == (unsigned) repha_category) - buffer->next_glyph (); + (void) buffer->next_glyph (); } (void) buffer->output_info (ginfo); } else - buffer->next_glyph (); + (void) buffer->next_glyph (); } buffer->swap_buffers (); } diff --git a/src/hb-ot-shape-complex-thai.cc b/src/hb-ot-shape-complex-thai.cc index 925e28d3b..4c3068173 100644 --- a/src/hb-ot-shape-complex-thai.cc +++ b/src/hb-ot-shape-complex-thai.cc @@ -323,16 +323,17 @@ preprocess_text_thai (const hb_ot_shape_plan_t *plan, buffer->clear_output (); 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; - if (likely (!IS_SARA_AM (u))) { - buffer->next_glyph (); + if (likely (!IS_SARA_AM (u))) + { + if (unlikely (!buffer->next_glyph ())) break; continue; } /* 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()); if (unlikely (!buffer->replace_glyph (SARA_AA_FROM_SARA_AM (u)))) break; diff --git a/src/hb-ot-shape-complex-vowel-constraints.cc b/src/hb-ot-shape-complex-vowel-constraints.cc index 2c61e976f..103762699 100644 --- a/src/hb-ot-shape-complex-vowel-constraints.cc +++ b/src/hb-ot-shape-complex-vowel-constraints.cc @@ -31,7 +31,7 @@ static void _output_with_dotted_circle (hb_buffer_t *buffer) { _output_dotted_circle (buffer); - buffer->next_glyph (); + (void) buffer->next_glyph (); } void @@ -96,12 +96,12 @@ _hb_preprocess_text_vowel_constraints (const hb_ot_shape_plan_t *plan HB_UNUSED, buffer->idx + 2 < count && 0x0907u == buffer->cur (2).codepoint) { - buffer->next_glyph (); + (void) buffer->next_glyph (); matched = true; } break; } - buffer->next_glyph (); + (void) buffer->next_glyph (); if (matched) _output_with_dotted_circle (buffer); } 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; break; } - buffer->next_glyph (); + (void) buffer->next_glyph (); if (matched) _output_with_dotted_circle (buffer); } break; @@ -158,7 +158,7 @@ _hb_preprocess_text_vowel_constraints (const hb_ot_shape_plan_t *plan HB_UNUSED, } break; } - buffer->next_glyph (); + (void) buffer->next_glyph (); if (matched) _output_with_dotted_circle (buffer); } 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; break; } - buffer->next_glyph (); + (void) buffer->next_glyph (); if (matched) _output_with_dotted_circle (buffer); } 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; break; } - buffer->next_glyph (); + (void) buffer->next_glyph (); if (matched) _output_with_dotted_circle (buffer); } break; @@ -214,7 +214,7 @@ _hb_preprocess_text_vowel_constraints (const hb_ot_shape_plan_t *plan HB_UNUSED, { matched = true; } - buffer->next_glyph (); + (void) buffer->next_glyph (); if (matched) _output_with_dotted_circle (buffer); } 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; break; } - buffer->next_glyph (); + (void) buffer->next_glyph (); if (matched) _output_with_dotted_circle (buffer); } 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; break; } - buffer->next_glyph (); + (void) buffer->next_glyph (); if (matched) _output_with_dotted_circle (buffer); } break; @@ -281,7 +281,7 @@ _hb_preprocess_text_vowel_constraints (const hb_ot_shape_plan_t *plan HB_UNUSED, } break; } - buffer->next_glyph (); + (void) buffer->next_glyph (); if (matched) _output_with_dotted_circle (buffer); } break; @@ -316,7 +316,7 @@ _hb_preprocess_text_vowel_constraints (const hb_ot_shape_plan_t *plan HB_UNUSED, } break; } - buffer->next_glyph (); + (void) buffer->next_glyph (); if (matched) _output_with_dotted_circle (buffer); } 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; break; } - buffer->next_glyph (); + (void) buffer->next_glyph (); if (matched) _output_with_dotted_circle (buffer); } break; @@ -358,7 +358,7 @@ _hb_preprocess_text_vowel_constraints (const hb_ot_shape_plan_t *plan HB_UNUSED, } break; } - buffer->next_glyph (); + (void) buffer->next_glyph (); if (matched) _output_with_dotted_circle (buffer); } break; @@ -384,7 +384,7 @@ _hb_preprocess_text_vowel_constraints (const hb_ot_shape_plan_t *plan HB_UNUSED, } break; } - buffer->next_glyph (); + (void) buffer->next_glyph (); if (matched) _output_with_dotted_circle (buffer); } break; @@ -404,7 +404,7 @@ _hb_preprocess_text_vowel_constraints (const hb_ot_shape_plan_t *plan HB_UNUSED, } break; } - buffer->next_glyph (); + (void) buffer->next_glyph (); if (matched) _output_with_dotted_circle (buffer); } 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; break; } - buffer->next_glyph (); + (void) buffer->next_glyph (); if (matched) _output_with_dotted_circle (buffer); } break; diff --git a/src/hb-ot-shape-normalize.cc b/src/hb-ot-shape-normalize.cc index 8ad2d771a..778b5b8bd 100644 --- a/src/hb-ot-shape-normalize.cc +++ b/src/hb-ot-shape-normalize.cc @@ -111,7 +111,7 @@ static inline void next_char (hb_buffer_t *buffer, hb_codepoint_t glyph) { buffer->cur().glyph_index() = glyph; - buffer->next_glyph (); + (void) buffer->next_glyph (); } 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. */ set_glyph (buffer->cur(), font); - buffer->next_glyph (); + (void) buffer->next_glyph (); set_glyph (buffer->cur(), font); - buffer->next_glyph (); + (void) buffer->next_glyph (); } /* 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); - buffer->next_glyph (); + (void) buffer->next_glyph (); } - } else { + } + else + { 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); - 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 (); count = buffer->len; unsigned int starter = 0; - buffer->next_glyph (); - while (buffer->idx < count && buffer->successful) + (void) buffer->next_glyph (); + while (buffer->idx < count /* No need for: && buffer->successful */) { hb_codepoint_t composed, glyph; 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)) { /* Composes. */ - buffer->next_glyph (); /* Copy to out-buffer. */ - if (unlikely (!buffer->successful)) - return; + if (unlikely (!buffer->next_glyph ())) break; /* Copy to out-buffer. */ buffer->merge_out_clusters (starter, buffer->out_len); buffer->out_len--; /* Remove the second composable. */ /* 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. */ - buffer->next_glyph (); + if (unlikely (!buffer->next_glyph ())) break; if (info_cc (buffer->prev()) == 0) starter = buffer->out_len - 1;