Compare commits

...

1 Commits

Author SHA1 Message Date
Behdad Esfahbod 1ec0f58297 [coverage] Add a static cache
Speeds up Roboto by around 5%; costs 2kb globally.
2023-01-30 16:48:29 -07:00
2 changed files with 25 additions and 0 deletions

View File

@ -30,6 +30,8 @@
#ifndef OT_LAYOUT_COMMON_COVERAGEFORMAT1_HH #ifndef OT_LAYOUT_COMMON_COVERAGEFORMAT1_HH
#define OT_LAYOUT_COMMON_COVERAGEFORMAT1_HH #define OT_LAYOUT_COMMON_COVERAGEFORMAT1_HH
#include "../../../hb-cache.hh"
namespace OT { namespace OT {
namespace Layout { namespace Layout {
namespace Common { namespace Common {
@ -57,8 +59,18 @@ struct CoverageFormat1_3
unsigned int get_coverage (hb_codepoint_t glyph_id) const unsigned int get_coverage (hb_codepoint_t glyph_id) const
{ {
static hb_cache_t<16, 8, 9, true> cache;
unsigned v;
if (cache.get ((glyph_id + (uintptr_t) this) & 0xFFFF, &v))
{
if (glyphArray[v] == glyph_id)
return v;
}
unsigned int i; unsigned int i;
glyphArray.bfind (glyph_id, &i, HB_NOT_FOUND_STORE, NOT_COVERED); glyphArray.bfind (glyph_id, &i, HB_NOT_FOUND_STORE, NOT_COVERED);
cache.set ((glyph_id + (uintptr_t) this) & 0xFFFF, i);
return i; return i;
} }

View File

@ -31,6 +31,8 @@
#include "RangeRecord.hh" #include "RangeRecord.hh"
#include "../../../hb-cache.hh"
namespace OT { namespace OT {
namespace Layout { namespace Layout {
namespace Common { namespace Common {
@ -59,7 +61,18 @@ struct CoverageFormat2_4
unsigned int get_coverage (hb_codepoint_t glyph_id) const unsigned int get_coverage (hb_codepoint_t glyph_id) const
{ {
static hb_cache_t<16, 8, 9, true> cache;
unsigned v;
if (cache.get ((glyph_id + (uintptr_t) this) & 0xFFFF, &v))
{
const RangeRecord<Types> &range = rangeRecord[v];
if (range.first <= glyph_id && glyph_id <= range.last)
return (unsigned int) range.value + (glyph_id - range.first);
}
const RangeRecord<Types> &range = rangeRecord.bsearch (glyph_id); const RangeRecord<Types> &range = rangeRecord.bsearch (glyph_id);
cache.set ((glyph_id + (uintptr_t) this) & 0xFFFF, &range - &rangeRecord[0]);
return likely (range.first <= range.last) return likely (range.first <= range.last)
? (unsigned int) range.value + (glyph_id - range.first) ? (unsigned int) range.value + (glyph_id - range.first)
: NOT_COVERED; : NOT_COVERED;