diff --git a/src/hb-buffer.cc b/src/hb-buffer.cc index 88e113760..7401213e3 100644 --- a/src/hb-buffer.cc +++ b/src/hb-buffer.cc @@ -301,10 +301,9 @@ hb_buffer_t::clear () memset (context, 0, sizeof context); memset (context_len, 0, sizeof context_len); - scratch_flags = HB_BUFFER_SCRATCH_FLAG_DEFAULT; - serial = 0; - deallocate_var_all (); + serial = 0; + scratch_flags = HB_BUFFER_SCRATCH_FLAG_DEFAULT; } void diff --git a/src/hb-buffer.hh b/src/hb-buffer.hh index 5a6417cc8..f2cbc7580 100644 --- a/src/hb-buffer.hh +++ b/src/hb-buffer.hh @@ -129,11 +129,14 @@ struct hb_buffer_t * Not part of content. */ +#ifndef HB_NDEBUG + uint8_t allocated_var_bits; +#endif + uint8_t serial; hb_buffer_scratch_flags_t scratch_flags; /* Have space-fallback, etc. */ - unsigned int serial; - unsigned int max_len; /* Maximum allowed len. */ 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 */ #ifndef HB_NO_BUFFER_MESSAGE @@ -145,11 +148,6 @@ struct hb_buffer_t static constexpr unsigned message_depth = 0u; #endif - /* Internal debugging. */ - /* The bits here reflect current allocations of the bytes in glyph_info_t's var1 and var2. */ -#ifndef HB_NDEBUG - uint8_t allocated_var_bits; -#endif /* Methods */ @@ -207,7 +205,7 @@ struct hb_buffer_t unsigned int backtrack_len () const { return have_output ? out_len : idx; } unsigned int lookahead_len () const { return len - idx; } - unsigned int next_serial () { return serial++; } + uint8_t next_serial () { return ++serial ? serial : ++serial; } HB_INTERNAL void add (hb_codepoint_t codepoint, unsigned int cluster); diff --git a/src/hb-ot-layout.hh b/src/hb-ot-layout.hh index 2c825e0c8..ede8f007d 100644 --- a/src/hb-ot-layout.hh +++ b/src/hb-ot-layout.hh @@ -482,10 +482,9 @@ _hb_glyph_info_get_lig_num_comps (const hb_glyph_info_t *info) } static inline uint8_t -_hb_allocate_lig_id (hb_buffer_t *buffer) { +_hb_allocate_lig_id (hb_buffer_t *buffer) +{ uint8_t lig_id = buffer->next_serial () & 0x07; - if (unlikely (!lig_id)) - lig_id = _hb_allocate_lig_id (buffer); /* in case of overflow */ return lig_id; } diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc index 4dde3520d..dc66d2c8c 100644 --- a/src/hb-ot-shape.cc +++ b/src/hb-ot-shape.cc @@ -1146,6 +1146,7 @@ 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))) { @@ -1191,6 +1192,7 @@ hb_ot_shape_internal (hb_ot_shape_context_t *c) 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; }