From 0c7fb7419c20d04b803412945565562c32b42929 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 25 Feb 2016 14:40:09 +0900 Subject: [PATCH] Speed up buffer variable allocation sanity check This makes defining HB_NDEBUG much less relevant, to the point of irrelevance. Sorry about all the fuss in previous release! --- src/hb-buffer-private.hh | 67 ++++++++++++++++++++++++-------------- src/hb-buffer.cc | 70 ---------------------------------------- 2 files changed, 43 insertions(+), 94 deletions(-) diff --git a/src/hb-buffer-private.hh b/src/hb-buffer-private.hh index fee594980..ed592f448 100644 --- a/src/hb-buffer-private.hh +++ b/src/hb-buffer-private.hh @@ -124,18 +124,46 @@ struct hb_buffer_t { void *message_data; hb_destroy_func_t message_destroy; -#ifndef HB_NDEBUG /* Internal debugging. */ - /* These reflect current allocations of the bytes in glyph_info_t's var1 and var2. */ - uint8_t allocated_var_bytes[8]; - const char *allocated_var_owner[8]; - HB_INTERNAL void allocate_var (unsigned int byte_i, unsigned int count, const char *owner); - HB_INTERNAL void deallocate_var (unsigned int byte_i, unsigned int count, const char *owner); - HB_INTERNAL void assert_var (unsigned int byte_i, unsigned int count, const char *owner); - HB_INTERNAL void deallocate_var_all (void); -#else - inline void deallocate_var_all (void) {} + /* 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 + inline void allocate_var (unsigned int start, unsigned int count) + { +#ifndef HB_NDEBUG + unsigned int end = start + count; + assert (end <= 8); + unsigned int bits = (1<func (offsetof (hb_glyph_info_t, var) - offsetof(hb_glyph_info_t, var1), \ - sizeof (b->info[0].var), owner) -#ifndef HB_NDEBUG -#define HB_BUFFER_ALLOCATE_VAR(b, var) \ - HB_BUFFER_XALLOCATE_VAR (b, allocate_var, var (), #var) -#define HB_BUFFER_DEALLOCATE_VAR(b, var) \ - HB_BUFFER_XALLOCATE_VAR (b, deallocate_var, var (), #var) -#define HB_BUFFER_ASSERT_VAR(b, var) \ - HB_BUFFER_XALLOCATE_VAR (b, assert_var, var (), #var) -#else -#define HB_BUFFER_ALLOCATE_VAR(b, var) -#define HB_BUFFER_DEALLOCATE_VAR(b, var) -#define HB_BUFFER_ASSERT_VAR(b, var) -#endif + 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 ()) #endif /* HB_BUFFER_PRIVATE_HH */ diff --git a/src/hb-buffer.cc b/src/hb-buffer.cc index ea639559f..406db9c84 100644 --- a/src/hb-buffer.cc +++ b/src/hb-buffer.cc @@ -661,76 +661,6 @@ hb_buffer_t::guess_segment_properties (void) } -#ifndef HB_NDEBUG -static inline void -dump_var_allocation (const hb_buffer_t *buffer) -{ - char buf[80]; - for (unsigned int i = 0; i < 8; i++) - buf[i] = '0' + buffer->allocated_var_bytes[7 - i]; - buf[8] = '\0'; - DEBUG_MSG (BUFFER, buffer, - "Current var allocation: %s", - buf); -} - -void hb_buffer_t::allocate_var (unsigned int byte_i, unsigned int count, const char *owner) -{ - assert (byte_i < 8 && byte_i + count <= 8); - - if (DEBUG_ENABLED (BUFFER)) - dump_var_allocation (this); - DEBUG_MSG (BUFFER, this, - "Allocating var bytes %d..%d for %s", - byte_i, byte_i + count - 1, owner); - - for (unsigned int i = byte_i; i < byte_i + count; i++) { - assert (!allocated_var_bytes[i]); - allocated_var_bytes[i]++; - allocated_var_owner[i] = owner; - } -} - -void hb_buffer_t::deallocate_var (unsigned int byte_i, unsigned int count, const char *owner) -{ - if (DEBUG_ENABLED (BUFFER)) - dump_var_allocation (this); - - DEBUG_MSG (BUFFER, this, - "Deallocating var bytes %d..%d for %s", - byte_i, byte_i + count - 1, owner); - - assert (byte_i < 8 && byte_i + count <= 8); - for (unsigned int i = byte_i; i < byte_i + count; i++) { - assert (allocated_var_bytes[i]); - assert (0 == strcmp (allocated_var_owner[i], owner)); - allocated_var_bytes[i]--; - } -} - -void hb_buffer_t::assert_var (unsigned int byte_i, unsigned int count, const char *owner) -{ - if (DEBUG_ENABLED (BUFFER)) - dump_var_allocation (this); - - DEBUG_MSG (BUFFER, this, - "Asserting var bytes %d..%d for %s", - byte_i, byte_i + count - 1, owner); - - assert (byte_i < 8 && byte_i + count <= 8); - for (unsigned int i = byte_i; i < byte_i + count; i++) { - assert (allocated_var_bytes[i]); - assert (0 == strcmp (allocated_var_owner[i], owner)); - } -} - -void hb_buffer_t::deallocate_var_all (void) -{ - memset (allocated_var_bytes, 0, sizeof (allocated_var_bytes)); - memset (allocated_var_owner, 0, sizeof (allocated_var_owner)); -} -#endif /* HB_NDEBUG */ - /* Public API */ /**