[buffer] Add assert_unicode()/assert_glyphs() and use internally

This commit is contained in:
Behdad Esfahbod 2020-10-15 02:02:04 -06:00
parent 5ef0613909
commit 77e704d1db
4 changed files with 20 additions and 16 deletions

View File

@ -476,8 +476,7 @@ hb_buffer_serialize_glyphs (hb_buffer_t *buffer,
if (buf_size) if (buf_size)
*buf = '\0'; *buf = '\0';
assert ((!buffer->len && (buffer->content_type == HB_BUFFER_CONTENT_TYPE_INVALID)) || buffer->assert_glyphs ();
(buffer->content_type == HB_BUFFER_CONTENT_TYPE_GLYPHS));
if (!buffer->have_positions) if (!buffer->have_positions)
flags |= HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS; flags |= HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS;
@ -574,8 +573,7 @@ hb_buffer_serialize_unicode (hb_buffer_t *buffer,
if (buf_size) if (buf_size)
*buf = '\0'; *buf = '\0';
assert ((!buffer->len && (buffer->content_type == HB_BUFFER_CONTENT_TYPE_INVALID)) || buffer->assert_unicode ();
(buffer->content_type == HB_BUFFER_CONTENT_TYPE_UNICODE));
if (unlikely (start == end)) if (unlikely (start == end))
return 0; return 0;
@ -749,8 +747,7 @@ hb_buffer_deserialize_glyphs (hb_buffer_t *buffer,
end_ptr = &end; end_ptr = &end;
*end_ptr = buf; *end_ptr = buf;
assert ((!buffer->len && (buffer->content_type == HB_BUFFER_CONTENT_TYPE_INVALID)) || buffer->assert_glyphs ();
(buffer->content_type == HB_BUFFER_CONTENT_TYPE_GLYPHS));
if (unlikely (hb_object_is_immutable (buffer))) if (unlikely (hb_object_is_immutable (buffer)))
{ {
@ -819,9 +816,7 @@ hb_buffer_deserialize_unicode (hb_buffer_t *buffer,
end_ptr = &end; end_ptr = &end;
*end_ptr = buf; *end_ptr = buf;
assert ((!buffer->len && (buffer->content_type == HB_BUFFER_CONTENT_TYPE_INVALID)) || buffer->assert_unicode ();
(buffer->content_type == HB_BUFFER_CONTENT_TYPE_UNICODE));
if (unlikely (hb_object_is_immutable (buffer))) if (unlikely (hb_object_is_immutable (buffer)))
{ {

View File

@ -617,8 +617,7 @@ hb_buffer_t::unsafe_to_break_from_outbuffer (unsigned int start, unsigned int en
void void
hb_buffer_t::guess_segment_properties () hb_buffer_t::guess_segment_properties ()
{ {
assert ((content_type == HB_BUFFER_CONTENT_TYPE_UNICODE) || assert_unicode ();
(!len && (content_type == HB_BUFFER_CONTENT_TYPE_INVALID)));
/* If script is set to INVALID, guess from buffer contents */ /* If script is set to INVALID, guess from buffer contents */
if (props.script == HB_SCRIPT_INVALID) { 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; typedef typename utf_t::codepoint_t T;
const hb_codepoint_t replacement = buffer->replacement; const hb_codepoint_t replacement = buffer->replacement;
assert ((buffer->content_type == HB_BUFFER_CONTENT_TYPE_UNICODE) || buffer->assert_unicode ();
(!buffer->len && (buffer->content_type == HB_BUFFER_CONTENT_TYPE_INVALID)));
if (unlikely (hb_object_is_immutable (buffer))) if (unlikely (hb_object_is_immutable (buffer)))
return; return;
@ -1853,8 +1851,8 @@ void
hb_buffer_normalize_glyphs (hb_buffer_t *buffer) hb_buffer_normalize_glyphs (hb_buffer_t *buffer)
{ {
assert (buffer->have_positions); 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); bool backward = HB_DIRECTION_IS_BACKWARD (buffer->props.direction);

View File

@ -339,6 +339,16 @@ struct hb_buffer_t
bool ensure_inplace (unsigned int size) bool ensure_inplace (unsigned int size)
{ return likely (!size || size < allocated); } { 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 () bool ensure_glyphs ()
{ {
if (unlikely (content_type != HB_BUFFER_CONTENT_TYPE_GLYPHS)) if (unlikely (content_type != HB_BUFFER_CONTENT_TYPE_GLYPHS))

View File

@ -401,7 +401,8 @@ _hb_shape_plan_execute_internal (hb_shape_plan_t *shape_plan,
return true; return true;
assert (!hb_object_is_immutable (buffer)); 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))) if (unlikely (hb_object_is_inert (shape_plan)))
return false; return false;