[sanitize/Coverage] Keep a map of sane coverages

Fonts like Gulzar reuse the same coverage over a thousand times
sometimes.

However, this doesn't speed up sanitize unfortunately. Looks
like calling Coverage::sanitize() is already very fast. We're
just doing A LOT of it.

The map slowed it down in fact. A set was even slower.

Going to revert.
pull/4337/head
Behdad Esfahbod 1 year ago
parent 7de2f515a0
commit 0ab906715e
  1. 22
      src/OT/Layout/Common/Coverage.hh
  2. 3
      src/hb-sanitize.hh

@ -62,18 +62,30 @@ struct Coverage
#endif #endif
bool sanitize (hb_sanitize_context_t *c) const bool sanitize (hb_sanitize_context_t *c) const
{ {
uintptr_t offset = (uintptr_t) this - (uintptr_t) c->start;
if (offset < HB_SET_VALUE_INVALID &&
c->sane_coverages.has ((hb_codepoint_t) offset))
return true;
bool ret;
TRACE_SANITIZE (this); TRACE_SANITIZE (this);
if (!u.format.sanitize (c)) return_trace (false); if (!u.format.sanitize (c)) return_trace (false);
switch (u.format) switch (u.format)
{ {
case 1: return_trace (u.format1.sanitize (c)); case 1: ret = u.format1.sanitize (c); break;
case 2: return_trace (u.format2.sanitize (c)); case 2: ret = u.format2.sanitize (c); break;
#ifndef HB_NO_BEYOND_64K #ifndef HB_NO_BEYOND_64K
case 3: return_trace (u.format3.sanitize (c)); case 3: ret = u.format3.sanitize (c); break;
case 4: return_trace (u.format4.sanitize (c)); case 4: ret = u.format4.sanitize (c); break;
#endif #endif
default:return_trace (true); default:ret = true; break;
} }
if (likely (offset < HB_SET_VALUE_INVALID && ret))
c->sane_coverages.set ((hb_codepoint_t) offset, 1);
return_trace (ret);
} }
/* Has interface. */ /* Has interface. */

@ -32,6 +32,7 @@
#include "hb.hh" #include "hb.hh"
#include "hb-blob.hh" #include "hb-blob.hh"
#include "hb-dispatch.hh" #include "hb-dispatch.hh"
#include "hb-map.hh"
/* /*
@ -228,6 +229,7 @@ struct hb_sanitize_context_t :
this->edit_count = 0; this->edit_count = 0;
this->debug_depth = 0; this->debug_depth = 0;
this->recursion_depth = 0; this->recursion_depth = 0;
this->sane_coverages.clear ();
DEBUG_MSG_LEVEL (SANITIZE, start, 0, +1, DEBUG_MSG_LEVEL (SANITIZE, start, 0, +1,
"start [%p..%p] (%lu bytes)", "start [%p..%p] (%lu bytes)",
@ -505,6 +507,7 @@ struct hb_sanitize_context_t :
bool num_glyphs_set; bool num_glyphs_set;
public: public:
bool lazy_some_gpos; bool lazy_some_gpos;
hb_map_t sane_coverages;
}; };
struct hb_sanitize_with_object_t struct hb_sanitize_with_object_t

Loading…
Cancel
Save