From 4d2813d3e980c8e6150caafa604a78cc44bf62a2 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 16 Apr 2013 21:57:21 -0400 Subject: [PATCH] Print set-digest hit ratio with HB_DEBUG_SET_DIGESTS --- src/hb-set-private.hh | 13 +++++++++++++ src/hb-set.cc | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/hb-set-private.hh b/src/hb-set-private.hh index 1241e053a..d9e0d2960 100644 --- a/src/hb-set-private.hh +++ b/src/hb-set-private.hh @@ -102,6 +102,10 @@ struct hb_set_digest_lowest_bits_t mask_t mask; }; +#ifdef HB_DEBUG_SET_DIGESTS +extern unsigned long digest_total, digest_yes, digest_yes1, digest_yes2; +#endif + struct hb_set_digest_t { ASSERT_POD (); @@ -122,6 +126,15 @@ struct hb_set_digest_t } inline bool may_have (hb_codepoint_t g) const { +#ifdef HB_DEBUG_SET_DIGESTS + digest_total++; + if (digest1.may_have (g) && digest2.may_have (g)) + digest_yes++; + if (digest1.may_have (g)) + digest_yes1++; + if (digest2.may_have (g)) + digest_yes2++; +#endif return digest1.may_have (g) && digest2.may_have (g); } diff --git a/src/hb-set.cc b/src/hb-set.cc index 5f427a5d8..050cc24eb 100644 --- a/src/hb-set.cc +++ b/src/hb-set.cc @@ -27,6 +27,19 @@ #include "hb-set-private.hh" +#ifdef HB_DEBUG_SET_DIGESTS +unsigned long digest_total, digest_yes, digest_yes1, digest_yes2; +__attribute__((__destructor__)) +void digest_print (void) +{ + if (!digest_total) + return; + printf("Set digest summary: both %%%ld first %%%ld second %%%ld\n", + 100 * digest_yes / digest_total, + 100 * digest_yes1 / digest_total, + 100 * digest_yes2 / digest_total); +} +#endif /* Public API */