Simplify tracing code when tracing is disabled

Fixes https://github.com/behdad/harfbuzz/pull/605
This commit is contained in:
Behdad Esfahbod 2017-11-03 17:16:26 -04:00
parent 40ec3bbb55
commit 5aad819433
2 changed files with 52 additions and 16 deletions

View File

@ -266,15 +266,13 @@ struct hb_auto_trace_t {
const void *obj; const void *obj;
bool returned; bool returned;
}; };
template <typename ret_t> /* Optimize when tracing is disabled */ template <typename ret_t> /* Make sure we don't use hb_auto_trace_t when not tracing. */
struct hb_auto_trace_t<0, ret_t> { 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,
...) {}
/* For disabled tracing; optimize out everything.
* https://github.com/behdad/harfbuzz/pull/605 */
template <typename ret_t>
struct hb_no_trace_t {
inline ret_t ret (ret_t v, unsigned int line HB_UNUSED = 0) { return v; } 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 #ifndef HB_DEBUG_APPLY
#define HB_DEBUG_APPLY (HB_DEBUG+0) #define HB_DEBUG_APPLY (HB_DEBUG+0)
#endif #endif
#if HB_DEBUG_APPLY
#define TRACE_APPLY(this) \ #define TRACE_APPLY(this) \
hb_auto_trace_t<HB_DEBUG_APPLY, bool> trace \ hb_auto_trace_t<HB_DEBUG_APPLY, bool> trace \
(&c->debug_depth, c->get_name (), this, HB_FUNC, \ (&c->debug_depth, c->get_name (), this, HB_FUNC, \
"idx %d gid %u lookup %d", \ "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<bool> trace
#endif
#ifndef HB_DEBUG_CLOSURE #ifndef HB_DEBUG_CLOSURE
#define HB_DEBUG_CLOSURE (HB_DEBUG+0) #define HB_DEBUG_CLOSURE (HB_DEBUG+0)
#endif #endif
#if HB_DEBUG_CLOSURE
#define TRACE_CLOSURE(this) \ #define TRACE_CLOSURE(this) \
hb_auto_trace_t<HB_DEBUG_CLOSURE, hb_void_t> trace \ hb_auto_trace_t<HB_DEBUG_CLOSURE, hb_void_t> trace \
(&c->debug_depth, c->get_name (), this, HB_FUNC, \ (&c->debug_depth, c->get_name (), this, HB_FUNC, \
""); "")
#else
#define TRACE_CLOSURE(this) hb_no_trace_t<hb_void_t> trace HB_UNUSED
#endif
#ifndef HB_DEBUG_COLLECT_GLYPHS #ifndef HB_DEBUG_COLLECT_GLYPHS
#define HB_DEBUG_COLLECT_GLYPHS (HB_DEBUG+0) #define HB_DEBUG_COLLECT_GLYPHS (HB_DEBUG+0)
#endif #endif
#if HB_DEBUG_COLLECT_GLYPHS
#define TRACE_COLLECT_GLYPHS(this) \ #define TRACE_COLLECT_GLYPHS(this) \
hb_auto_trace_t<HB_DEBUG_COLLECT_GLYPHS, hb_void_t> trace \ hb_auto_trace_t<HB_DEBUG_COLLECT_GLYPHS, hb_void_t> trace \
(&c->debug_depth, c->get_name (), this, HB_FUNC, \ (&c->debug_depth, c->get_name (), this, HB_FUNC, \
""); "")
#else
#define TRACE_COLLECT_GLYPHS(this) hb_no_trace_t<hb_void_t> trace HB_UNUSED
#endif
#ifndef HB_DEBUG_SANITIZE #ifndef HB_DEBUG_SANITIZE
#define HB_DEBUG_SANITIZE (HB_DEBUG+0) #define HB_DEBUG_SANITIZE (HB_DEBUG+0)
#endif #endif
#if HB_DEBUG_SANITIZE
#define TRACE_SANITIZE(this) \ #define TRACE_SANITIZE(this) \
hb_auto_trace_t<HB_DEBUG_SANITIZE, bool> trace \ hb_auto_trace_t<HB_DEBUG_SANITIZE, bool> trace \
(&c->debug_depth, c->get_name (), this, HB_FUNC, \ (&c->debug_depth, c->get_name (), this, HB_FUNC, \
""); "");
#else
#define TRACE_SANITIZE(this) hb_no_trace_t<bool> trace
#endif
#ifndef HB_DEBUG_SERIALIZE #ifndef HB_DEBUG_SERIALIZE
#define HB_DEBUG_SERIALIZE (HB_DEBUG+0) #define HB_DEBUG_SERIALIZE (HB_DEBUG+0)
#endif #endif
#if HB_DEBUG_SERIALIZE
#define TRACE_SERIALIZE(this) \ #define TRACE_SERIALIZE(this) \
hb_auto_trace_t<HB_DEBUG_SERIALIZE, bool> trace \ hb_auto_trace_t<HB_DEBUG_SERIALIZE, bool> trace \
(&c->debug_depth, "SERIALIZE", c, HB_FUNC, \ (&c->debug_depth, "SERIALIZE", c, HB_FUNC, \
""); "");
#else
#define TRACE_SERIALIZE(this) hb_no_trace_t<bool> trace
#endif
#ifndef HB_DEBUG_WOULD_APPLY #ifndef HB_DEBUG_WOULD_APPLY
#define HB_DEBUG_WOULD_APPLY (HB_DEBUG+0) #define HB_DEBUG_WOULD_APPLY (HB_DEBUG+0)
#endif #endif
#if HB_DEBUG_WOULD_APPLY
#define TRACE_WOULD_APPLY(this) \ #define TRACE_WOULD_APPLY(this) \
hb_auto_trace_t<HB_DEBUG_WOULD_APPLY, bool> trace \ hb_auto_trace_t<HB_DEBUG_WOULD_APPLY, bool> trace \
(&c->debug_depth, c->get_name (), this, HB_FUNC, \ (&c->debug_depth, c->get_name (), this, HB_FUNC, \
"%d glyphs", c->len); "%d glyphs", c->len);
#else
#define TRACE_WOULD_APPLY(this) hb_no_trace_t<bool> 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) \ #define TRACE_DISPATCH(this, format) \
hb_auto_trace_t<context_t::max_debug_depth, typename context_t::return_t> trace \ hb_auto_trace_t<context_t::max_debug_depth, typename context_t::return_t> trace \
(&c->debug_depth, c->get_name (), this, HB_FUNC, \ (&c->debug_depth, c->get_name (), this, HB_FUNC, \
"format %d", (int) format); "format %d", (int) format);
#else
#define TRACE_DISPATCH(this, format) hb_no_trace_t<typename context_t::return_t> trace
#endif
#endif /* HB_DEBUG_HH */ #endif /* HB_DEBUG_HH */

View File

@ -1205,11 +1205,11 @@ struct Rule
inline bool sanitize (hb_sanitize_context_t *c) const inline bool sanitize (hb_sanitize_context_t *c) const
{ {
TRACE_SANITIZE (this); TRACE_SANITIZE (this);
return inputCount.sanitize (c) return_trace (inputCount.sanitize (c) &&
&& lookupCount.sanitize (c) lookupCount.sanitize (c) &&
&& c->check_range (inputZ, c->check_range (inputZ,
inputZ[0].static_size * inputCount inputZ[0].static_size * inputCount +
+ lookupRecordX[0].static_size * lookupCount); lookupRecordX[0].static_size * lookupCount));
} }
protected: protected: