diff --git a/src/hb-buffer.cc b/src/hb-buffer.cc index 7401213e3..f5c709043 100644 --- a/src/hb-buffer.cc +++ b/src/hb-buffer.cc @@ -306,6 +306,33 @@ hb_buffer_t::clear () 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 hb_buffer_t::add (hb_codepoint_t codepoint, unsigned int cluster) diff --git a/src/hb-buffer.hh b/src/hb-buffer.hh index f2cbc7580..7d3ef34a2 100644 --- a/src/hb-buffer.hh +++ b/src/hb-buffer.hh @@ -125,8 +125,9 @@ struct hb_buffer_t hb_codepoint_t context[2][CONTEXT_LENGTH]; unsigned int context_len[2]; + /* - * Not part of content. + * Managed by enter / leave */ #ifndef HB_NDEBUG @@ -138,7 +139,11 @@ struct hb_buffer_t int max_ops; /* Maximum allowed operations. */ /* 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 hb_buffer_message_func_t message_func; void *message_data; @@ -203,6 +208,10 @@ struct hb_buffer_t HB_INTERNAL void reset (); 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 lookahead_len () const { return len - idx; } uint8_t next_serial () { return ++serial ? serial : ++serial; } diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc index dc66d2c8c..11fcc11f9 100644 --- a/src/hb-ot-shape.cc +++ b/src/hb-ot-shape.cc @@ -1145,19 +1145,7 @@ hb_propagate_flags (hb_buffer_t *buffer) static void hb_ot_shape_internal (hb_ot_shape_context_t *c) { - c->buffer->deallocate_var_all (); - 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); - } + c->buffer->enter (); /* Save the original direction, we use it later. */ 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->max_len = HB_BUFFER_MAX_LEN_DEFAULT; - c->buffer->max_ops = HB_BUFFER_MAX_OPS_DEFAULT; - c->buffer->deallocate_var_all (); - c->buffer->serial = 0; + c->buffer->leave (); }