From 5aad81943329df199501e9473e2cc39f9d4421a1 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 3 Nov 2017 17:16:26 -0400 Subject: [PATCH] Simplify tracing code when tracing is disabled Fixes https://github.com/behdad/harfbuzz/pull/605 --- src/hb-debug.hh | 58 ++++++++++++++++++++++------ src/hb-ot-layout-gsubgpos-private.hh | 10 ++--- 2 files changed, 52 insertions(+), 16 deletions(-) diff --git a/src/hb-debug.hh b/src/hb-debug.hh index c8cbee429..ca8c638a7 100644 --- a/src/hb-debug.hh +++ b/src/hb-debug.hh @@ -266,15 +266,13 @@ struct hb_auto_trace_t { const void *obj; bool returned; }; -template /* Optimize when tracing is disabled */ -struct hb_auto_trace_t<0, ret_t> { - explicit inline hb_auto_trace_t (unsigned int *plevel_ HB_UNUSED, - const char *what HB_UNUSED, - const void *obj HB_UNUSED, - const char *func HB_UNUSED, - const char *message HB_UNUSED, - ...) {} +template /* Make sure we don't use hb_auto_trace_t when not tracing. */ +struct hb_auto_trace_t<0, ret_t>; +/* For disabled tracing; optimize out everything. + * https://github.com/behdad/harfbuzz/pull/605 */ +template +struct hb_no_trace_t { inline ret_t ret (ret_t v, unsigned int line HB_UNUSED = 0) { return v; } }; @@ -328,56 +326,94 @@ struct hb_auto_trace_t<0, ret_t> { #ifndef HB_DEBUG_APPLY #define HB_DEBUG_APPLY (HB_DEBUG+0) #endif +#if HB_DEBUG_APPLY #define TRACE_APPLY(this) \ hb_auto_trace_t trace \ (&c->debug_depth, c->get_name (), this, HB_FUNC, \ "idx %d gid %u lookup %d", \ - c->buffer->idx, c->buffer->cur().codepoint, (int) c->lookup_index); + c->buffer->idx, c->buffer->cur().codepoint, (int) c->lookup_index) +#else +#define TRACE_APPLY(this) hb_no_trace_t trace +#endif #ifndef HB_DEBUG_CLOSURE #define HB_DEBUG_CLOSURE (HB_DEBUG+0) #endif +#if HB_DEBUG_CLOSURE #define TRACE_CLOSURE(this) \ hb_auto_trace_t trace \ (&c->debug_depth, c->get_name (), this, HB_FUNC, \ - ""); + "") +#else +#define TRACE_CLOSURE(this) hb_no_trace_t trace HB_UNUSED +#endif #ifndef HB_DEBUG_COLLECT_GLYPHS #define HB_DEBUG_COLLECT_GLYPHS (HB_DEBUG+0) #endif +#if HB_DEBUG_COLLECT_GLYPHS #define TRACE_COLLECT_GLYPHS(this) \ hb_auto_trace_t trace \ (&c->debug_depth, c->get_name (), this, HB_FUNC, \ - ""); + "") +#else +#define TRACE_COLLECT_GLYPHS(this) hb_no_trace_t trace HB_UNUSED +#endif #ifndef HB_DEBUG_SANITIZE #define HB_DEBUG_SANITIZE (HB_DEBUG+0) #endif +#if HB_DEBUG_SANITIZE #define TRACE_SANITIZE(this) \ hb_auto_trace_t trace \ (&c->debug_depth, c->get_name (), this, HB_FUNC, \ ""); +#else +#define TRACE_SANITIZE(this) hb_no_trace_t trace +#endif #ifndef HB_DEBUG_SERIALIZE #define HB_DEBUG_SERIALIZE (HB_DEBUG+0) #endif +#if HB_DEBUG_SERIALIZE #define TRACE_SERIALIZE(this) \ hb_auto_trace_t trace \ (&c->debug_depth, "SERIALIZE", c, HB_FUNC, \ ""); +#else +#define TRACE_SERIALIZE(this) hb_no_trace_t trace +#endif #ifndef HB_DEBUG_WOULD_APPLY #define HB_DEBUG_WOULD_APPLY (HB_DEBUG+0) #endif +#if HB_DEBUG_WOULD_APPLY #define TRACE_WOULD_APPLY(this) \ hb_auto_trace_t trace \ (&c->debug_depth, c->get_name (), this, HB_FUNC, \ "%d glyphs", c->len); +#else +#define TRACE_WOULD_APPLY(this) hb_no_trace_t trace +#endif +#ifndef HB_DEBUG_DISPATCH +#define HB_DEBUG_DISPATCH ( \ + HB_DEBUG_APPLY + \ + HB_DEBUG_CLOSURE + \ + HB_DEBUG_COLLECT_GLYPHS + \ + HB_DEBUG_SANITIZE + \ + HB_DEBUG_SERIALIZE + \ + HB_DEBUG_WOULD_APPLY + \ + 0) +#endif +#if HB_DEBUG_DISPATCH #define TRACE_DISPATCH(this, format) \ hb_auto_trace_t trace \ (&c->debug_depth, c->get_name (), this, HB_FUNC, \ "format %d", (int) format); +#else +#define TRACE_DISPATCH(this, format) hb_no_trace_t trace +#endif #endif /* HB_DEBUG_HH */ diff --git a/src/hb-ot-layout-gsubgpos-private.hh b/src/hb-ot-layout-gsubgpos-private.hh index 367b4d77a..b0cffa3a8 100644 --- a/src/hb-ot-layout-gsubgpos-private.hh +++ b/src/hb-ot-layout-gsubgpos-private.hh @@ -1205,11 +1205,11 @@ struct Rule inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return inputCount.sanitize (c) - && lookupCount.sanitize (c) - && c->check_range (inputZ, - inputZ[0].static_size * inputCount - + lookupRecordX[0].static_size * lookupCount); + return_trace (inputCount.sanitize (c) && + lookupCount.sanitize (c) && + c->check_range (inputZ, + inputZ[0].static_size * inputCount + + lookupRecordX[0].static_size * lookupCount)); } protected: