[buffer] Add try_allocate for buffer variables
This commit is contained in:
parent
b5f621b08d
commit
104dc85a22
|
@ -132,9 +132,7 @@ struct hb_buffer_t
|
|||
* Managed by enter / leave
|
||||
*/
|
||||
|
||||
#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 max_len; /* Maximum allowed len. */
|
||||
|
@ -163,38 +161,40 @@ struct hb_buffer_t
|
|||
|
||||
void allocate_var (unsigned int start, unsigned int count)
|
||||
{
|
||||
#ifndef HB_NDEBUG
|
||||
unsigned int end = start + count;
|
||||
assert (end <= 8);
|
||||
unsigned int bits = (1u<<end) - (1u<<start);
|
||||
assert (0 == (allocated_var_bits & bits));
|
||||
allocated_var_bits |= bits;
|
||||
#endif
|
||||
}
|
||||
bool try_allocate_var (unsigned int start, unsigned int count)
|
||||
{
|
||||
unsigned int end = start + count;
|
||||
assert (end <= 8);
|
||||
unsigned int bits = (1u<<end) - (1u<<start);
|
||||
if (allocated_var_bits & bits)
|
||||
return false;
|
||||
allocated_var_bits |= bits;
|
||||
return true;
|
||||
}
|
||||
void deallocate_var (unsigned int start, unsigned int count)
|
||||
{
|
||||
#ifndef HB_NDEBUG
|
||||
unsigned int end = start + count;
|
||||
assert (end <= 8);
|
||||
unsigned int bits = (1u<<end) - (1u<<start);
|
||||
assert (bits == (allocated_var_bits & bits));
|
||||
allocated_var_bits &= ~bits;
|
||||
#endif
|
||||
}
|
||||
void assert_var (unsigned int start, unsigned int count)
|
||||
{
|
||||
#ifndef HB_NDEBUG
|
||||
unsigned int end = start + count;
|
||||
assert (end <= 8);
|
||||
HB_UNUSED unsigned int bits = (1u<<end) - (1u<<start);
|
||||
assert (bits == (allocated_var_bits & bits));
|
||||
#endif
|
||||
}
|
||||
void deallocate_var_all ()
|
||||
{
|
||||
#ifndef HB_NDEBUG
|
||||
allocated_var_bits = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
hb_glyph_info_t &cur (unsigned int i = 0) { return info[idx + i]; }
|
||||
|
@ -621,9 +621,10 @@ DECLARE_NULL_INSTANCE (hb_buffer_t);
|
|||
#define HB_BUFFER_XALLOCATE_VAR(b, func, var) \
|
||||
b->func (offsetof (hb_glyph_info_t, var) - offsetof(hb_glyph_info_t, var1), \
|
||||
sizeof (b->info[0].var))
|
||||
#define HB_BUFFER_ALLOCATE_VAR(b, var) HB_BUFFER_XALLOCATE_VAR (b, allocate_var, var ())
|
||||
#define HB_BUFFER_DEALLOCATE_VAR(b, var) HB_BUFFER_XALLOCATE_VAR (b, deallocate_var, var ())
|
||||
#define HB_BUFFER_ASSERT_VAR(b, var) HB_BUFFER_XALLOCATE_VAR (b, assert_var, var ())
|
||||
#define HB_BUFFER_ALLOCATE_VAR(b, var) HB_BUFFER_XALLOCATE_VAR (b, allocate_var, var ())
|
||||
#define HB_BUFFER_TRY_ALLOCATE_VAR(b, var) HB_BUFFER_XALLOCATE_VAR (b, try_allocate_var, var ())
|
||||
#define HB_BUFFER_DEALLOCATE_VAR(b, var) HB_BUFFER_XALLOCATE_VAR (b, deallocate_var, var ())
|
||||
#define HB_BUFFER_ASSERT_VAR(b, var) HB_BUFFER_XALLOCATE_VAR (b, assert_var, var ())
|
||||
|
||||
|
||||
#endif /* HB_BUFFER_HH */
|
||||
|
|
Loading…
Reference in New Issue