[buffer] Add enter()/leave() pair around shape()

pull/3353/head
Behdad Esfahbod 3 years ago
parent 43be5ba442
commit d1e7df5c3f
  1. 27
      src/hb-buffer.cc
  2. 13
      src/hb-buffer.hh
  3. 19
      src/hb-ot-shape.cc

@ -306,6 +306,33 @@ hb_buffer_t::clear ()
scratch_flags = HB_BUFFER_SCRATCH_FLAG_DEFAULT; scratch_flags = HB_BUFFER_SCRATCH_FLAG_DEFAULT;
} }
void
hb_buffer_t::enter ()
{
deallocate_var_all ();
serial = 0;
scratch_flags = HB_BUFFER_SCRATCH_FLAG_DEFAULT;
if (likely (!hb_unsigned_mul_overflows (len, HB_BUFFER_MAX_LEN_FACTOR)))
{
max_len = hb_max (len * HB_BUFFER_MAX_LEN_FACTOR,
(unsigned) HB_BUFFER_MAX_LEN_MIN);
}
if (likely (!hb_unsigned_mul_overflows (len, HB_BUFFER_MAX_OPS_FACTOR)))
{
max_ops = hb_max (len * HB_BUFFER_MAX_OPS_FACTOR,
(unsigned) HB_BUFFER_MAX_OPS_MIN);
}
}
void
hb_buffer_t::leave ()
{
max_len = HB_BUFFER_MAX_LEN_DEFAULT;
max_ops = HB_BUFFER_MAX_OPS_DEFAULT;
deallocate_var_all ();
serial = 0;
}
void void
hb_buffer_t::add (hb_codepoint_t codepoint, hb_buffer_t::add (hb_codepoint_t codepoint,
unsigned int cluster) unsigned int cluster)

@ -125,8 +125,9 @@ struct hb_buffer_t
hb_codepoint_t context[2][CONTEXT_LENGTH]; hb_codepoint_t context[2][CONTEXT_LENGTH];
unsigned int context_len[2]; unsigned int context_len[2];
/* /*
* Not part of content. * Managed by enter / leave
*/ */
#ifndef HB_NDEBUG #ifndef HB_NDEBUG
@ -138,7 +139,11 @@ struct hb_buffer_t
int max_ops; /* Maximum allowed operations. */ int max_ops; /* Maximum allowed operations. */
/* The bits here reflect current allocations of the bytes in glyph_info_t's var1 and var2. */ /* The bits here reflect current allocations of the bytes in glyph_info_t's var1 and var2. */
/* Debugging API */
/*
* Messaging callback
*/
#ifndef HB_NO_BUFFER_MESSAGE #ifndef HB_NO_BUFFER_MESSAGE
hb_buffer_message_func_t message_func; hb_buffer_message_func_t message_func;
void *message_data; void *message_data;
@ -203,6 +208,10 @@ struct hb_buffer_t
HB_INTERNAL void reset (); HB_INTERNAL void reset ();
HB_INTERNAL void clear (); HB_INTERNAL void clear ();
/* Called around shape() */
HB_INTERNAL void enter ();
HB_INTERNAL void leave ();
unsigned int backtrack_len () const { return have_output ? out_len : idx; } unsigned int backtrack_len () const { return have_output ? out_len : idx; }
unsigned int lookahead_len () const { return len - idx; } unsigned int lookahead_len () const { return len - idx; }
uint8_t next_serial () { return ++serial ? serial : ++serial; } uint8_t next_serial () { return ++serial ? serial : ++serial; }

@ -1145,19 +1145,7 @@ hb_propagate_flags (hb_buffer_t *buffer)
static void static void
hb_ot_shape_internal (hb_ot_shape_context_t *c) hb_ot_shape_internal (hb_ot_shape_context_t *c)
{ {
c->buffer->deallocate_var_all (); c->buffer->enter ();
c->buffer->serial = 0;
c->buffer->scratch_flags = HB_BUFFER_SCRATCH_FLAG_DEFAULT;
if (likely (!hb_unsigned_mul_overflows (c->buffer->len, HB_BUFFER_MAX_LEN_FACTOR)))
{
c->buffer->max_len = hb_max (c->buffer->len * HB_BUFFER_MAX_LEN_FACTOR,
(unsigned) HB_BUFFER_MAX_LEN_MIN);
}
if (likely (!hb_unsigned_mul_overflows (c->buffer->len, HB_BUFFER_MAX_OPS_FACTOR)))
{
c->buffer->max_ops = hb_max (c->buffer->len * HB_BUFFER_MAX_OPS_FACTOR,
(unsigned) HB_BUFFER_MAX_OPS_MIN);
}
/* Save the original direction, we use it later. */ /* Save the original direction, we use it later. */
c->target_direction = c->buffer->props.direction; c->target_direction = c->buffer->props.direction;
@ -1189,10 +1177,7 @@ hb_ot_shape_internal (hb_ot_shape_context_t *c)
c->buffer->props.direction = c->target_direction; c->buffer->props.direction = c->target_direction;
c->buffer->max_len = HB_BUFFER_MAX_LEN_DEFAULT; c->buffer->leave ();
c->buffer->max_ops = HB_BUFFER_MAX_OPS_DEFAULT;
c->buffer->deallocate_var_all ();
c->buffer->serial = 0;
} }

Loading…
Cancel
Save