From 77e704d1dbfbdb6c54127112814b24358ec52eea Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 15 Oct 2020 02:02:04 -0600 Subject: [PATCH] [buffer] Add assert_unicode()/assert_glyphs() and use internally --- src/hb-buffer-serialize.cc | 13 ++++--------- src/hb-buffer.cc | 10 ++++------ src/hb-buffer.hh | 10 ++++++++++ src/hb-shape-plan.cc | 3 ++- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/hb-buffer-serialize.cc b/src/hb-buffer-serialize.cc index cd87dae9e..294b65e42 100644 --- a/src/hb-buffer-serialize.cc +++ b/src/hb-buffer-serialize.cc @@ -476,8 +476,7 @@ hb_buffer_serialize_glyphs (hb_buffer_t *buffer, if (buf_size) *buf = '\0'; - assert ((!buffer->len && (buffer->content_type == HB_BUFFER_CONTENT_TYPE_INVALID)) || - (buffer->content_type == HB_BUFFER_CONTENT_TYPE_GLYPHS)); + buffer->assert_glyphs (); if (!buffer->have_positions) flags |= HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS; @@ -574,8 +573,7 @@ hb_buffer_serialize_unicode (hb_buffer_t *buffer, if (buf_size) *buf = '\0'; - assert ((!buffer->len && (buffer->content_type == HB_BUFFER_CONTENT_TYPE_INVALID)) || - (buffer->content_type == HB_BUFFER_CONTENT_TYPE_UNICODE)); + buffer->assert_unicode (); if (unlikely (start == end)) return 0; @@ -749,8 +747,7 @@ hb_buffer_deserialize_glyphs (hb_buffer_t *buffer, end_ptr = &end; *end_ptr = buf; - assert ((!buffer->len && (buffer->content_type == HB_BUFFER_CONTENT_TYPE_INVALID)) || - (buffer->content_type == HB_BUFFER_CONTENT_TYPE_GLYPHS)); + buffer->assert_glyphs (); if (unlikely (hb_object_is_immutable (buffer))) { @@ -819,9 +816,7 @@ hb_buffer_deserialize_unicode (hb_buffer_t *buffer, end_ptr = &end; *end_ptr = buf; - assert ((!buffer->len && (buffer->content_type == HB_BUFFER_CONTENT_TYPE_INVALID)) || - (buffer->content_type == HB_BUFFER_CONTENT_TYPE_UNICODE)); - + buffer->assert_unicode (); if (unlikely (hb_object_is_immutable (buffer))) { diff --git a/src/hb-buffer.cc b/src/hb-buffer.cc index 9557eccc7..488f49147 100644 --- a/src/hb-buffer.cc +++ b/src/hb-buffer.cc @@ -617,8 +617,7 @@ hb_buffer_t::unsafe_to_break_from_outbuffer (unsigned int start, unsigned int en void hb_buffer_t::guess_segment_properties () { - assert ((content_type == HB_BUFFER_CONTENT_TYPE_UNICODE) || - (!len && (content_type == HB_BUFFER_CONTENT_TYPE_INVALID))); + assert_unicode (); /* If script is set to INVALID, guess from buffer contents */ if (props.script == HB_SCRIPT_INVALID) { @@ -1532,8 +1531,7 @@ hb_buffer_add_utf (hb_buffer_t *buffer, typedef typename utf_t::codepoint_t T; const hb_codepoint_t replacement = buffer->replacement; - assert ((buffer->content_type == HB_BUFFER_CONTENT_TYPE_UNICODE) || - (!buffer->len && (buffer->content_type == HB_BUFFER_CONTENT_TYPE_INVALID))); + buffer->assert_unicode (); if (unlikely (hb_object_is_immutable (buffer))) return; @@ -1853,8 +1851,8 @@ void hb_buffer_normalize_glyphs (hb_buffer_t *buffer) { assert (buffer->have_positions); - assert ((buffer->content_type == HB_BUFFER_CONTENT_TYPE_GLYPHS) || - (!buffer->len && (buffer->content_type == HB_BUFFER_CONTENT_TYPE_INVALID))); + + buffer->assert_glyphs (); bool backward = HB_DIRECTION_IS_BACKWARD (buffer->props.direction); diff --git a/src/hb-buffer.hh b/src/hb-buffer.hh index 86edb941e..9cad5206e 100644 --- a/src/hb-buffer.hh +++ b/src/hb-buffer.hh @@ -339,6 +339,16 @@ struct hb_buffer_t bool ensure_inplace (unsigned int size) { return likely (!size || size < allocated); } + void assert_glyphs () + { + assert ((content_type == HB_BUFFER_CONTENT_TYPE_GLYPHS) || + (!len && (content_type == HB_BUFFER_CONTENT_TYPE_INVALID))); + } + void assert_unicode () + { + assert ((content_type == HB_BUFFER_CONTENT_TYPE_UNICODE) || + (!len && (content_type == HB_BUFFER_CONTENT_TYPE_INVALID))); + } bool ensure_glyphs () { if (unlikely (content_type != HB_BUFFER_CONTENT_TYPE_GLYPHS)) diff --git a/src/hb-shape-plan.cc b/src/hb-shape-plan.cc index 2e03003dd..f893c4a3f 100644 --- a/src/hb-shape-plan.cc +++ b/src/hb-shape-plan.cc @@ -401,7 +401,8 @@ _hb_shape_plan_execute_internal (hb_shape_plan_t *shape_plan, return true; assert (!hb_object_is_immutable (buffer)); - assert (buffer->content_type == HB_BUFFER_CONTENT_TYPE_UNICODE); + + buffer->assert_unicode (); if (unlikely (hb_object_is_inert (shape_plan))) return false;