Disable internal buffer variable bookkeeping in NDEBUG builds

Saves some sweet time and binary size!
This commit is contained in:
Behdad Esfahbod 2016-02-25 12:23:02 +09:00
parent 94dd0bb7e7
commit 988165021f
3 changed files with 25 additions and 12 deletions

View File

@ -130,6 +130,7 @@ pkgconfig_DATA = harfbuzz.pc
EXTRA_DIST += harfbuzz.pc.in EXTRA_DIST += harfbuzz.pc.in
FUZZING_CPPFLAGS= \ FUZZING_CPPFLAGS= \
-DNDEBUG \
-DHB_MAX_NESTING_LEVEL=3 \ -DHB_MAX_NESTING_LEVEL=3 \
-DHB_SANITIZE_MAX_EDITS=3 \ -DHB_SANITIZE_MAX_EDITS=3 \
-DHB_BUFFER_MAX_EXPANSION_FACTOR=3 \ -DHB_BUFFER_MAX_EXPANSION_FACTOR=3 \

View File

@ -112,10 +112,6 @@ struct hb_buffer_t {
unsigned int serial; unsigned int serial;
/* 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];
/* Text before / after the main buffer contents. /* Text before / after the main buffer contents.
* Always in Unicode, and ordered outward. * Always in Unicode, and ordered outward.
* Index 0 is for "pre-context", 1 for "post-context". */ * Index 0 is for "pre-context", 1 for "post-context". */
@ -123,11 +119,24 @@ 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];
/* Debugging */ /* Debugging API */
hb_buffer_message_func_t message_func; hb_buffer_message_func_t message_func;
void *message_data; void *message_data;
hb_destroy_func_t message_destroy; hb_destroy_func_t message_destroy;
#ifndef 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) {}
#endif
/* Methods */ /* Methods */
@ -140,11 +149,6 @@ struct hb_buffer_t {
{ return len - idx; } { return len - idx; }
inline unsigned int next_serial (void) { return serial++; } inline unsigned int next_serial (void) { return serial++; }
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);
HB_INTERNAL void add (hb_codepoint_t codepoint, HB_INTERNAL void add (hb_codepoint_t codepoint,
unsigned int cluster); unsigned int cluster);
HB_INTERNAL void add_info (const hb_glyph_info_t &glyph_info); HB_INTERNAL void add_info (const hb_glyph_info_t &glyph_info);
@ -256,12 +260,18 @@ struct hb_buffer_t {
#define HB_BUFFER_XALLOCATE_VAR(b, func, var, owner) \ #define HB_BUFFER_XALLOCATE_VAR(b, func, var, owner) \
b->func (offsetof (hb_glyph_info_t, var) - offsetof(hb_glyph_info_t, var1), \ b->func (offsetof (hb_glyph_info_t, var) - offsetof(hb_glyph_info_t, var1), \
sizeof (b->info[0].var), owner) sizeof (b->info[0].var), owner)
#ifndef NDEBUG
#define HB_BUFFER_ALLOCATE_VAR(b, var) \ #define HB_BUFFER_ALLOCATE_VAR(b, var) \
HB_BUFFER_XALLOCATE_VAR (b, allocate_var, var (), #var) HB_BUFFER_XALLOCATE_VAR (b, allocate_var, var (), #var)
#define HB_BUFFER_DEALLOCATE_VAR(b, var) \ #define HB_BUFFER_DEALLOCATE_VAR(b, var) \
HB_BUFFER_XALLOCATE_VAR (b, deallocate_var, var (), #var) HB_BUFFER_XALLOCATE_VAR (b, deallocate_var, var (), #var)
#define HB_BUFFER_ASSERT_VAR(b, var) \ #define HB_BUFFER_ASSERT_VAR(b, var) \
HB_BUFFER_XALLOCATE_VAR (b, assert_var, var (), #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
#endif /* HB_BUFFER_PRIVATE_HH */ #endif /* HB_BUFFER_PRIVATE_HH */

View File

@ -242,11 +242,11 @@ hb_buffer_t::clear (void)
out_info = info; out_info = info;
serial = 0; serial = 0;
memset (allocated_var_bytes, 0, sizeof allocated_var_bytes);
memset (allocated_var_owner, 0, sizeof allocated_var_owner);
memset (context, 0, sizeof context); memset (context, 0, sizeof context);
memset (context_len, 0, sizeof context_len); memset (context_len, 0, sizeof context_len);
deallocate_var_all ();
} }
void void
@ -661,6 +661,7 @@ hb_buffer_t::guess_segment_properties (void)
} }
#ifndef NDEBUG
static inline void static inline void
dump_var_allocation (const hb_buffer_t *buffer) dump_var_allocation (const hb_buffer_t *buffer)
{ {
@ -728,6 +729,7 @@ void hb_buffer_t::deallocate_var_all (void)
memset (allocated_var_bytes, 0, sizeof (allocated_var_bytes)); memset (allocated_var_bytes, 0, sizeof (allocated_var_bytes));
memset (allocated_var_owner, 0, sizeof (allocated_var_owner)); memset (allocated_var_owner, 0, sizeof (allocated_var_owner));
} }
#endif /* NDEBUG */
/* Public API */ /* Public API */