[contextual] Use a binary coverage cache (in format2)

Reduces cache size by half.

Since we discard the actual coverage number anyway.
This commit is contained in:
Behdad Esfahbod committed 2025-12-20 17:08:48 -07:00
1 parent f9971108eb
commit d15bc8d4e9
4 files changed
+32 -10

No files matched your search

+15
View File
@@ -111,6 +111,21 @@ struct Coverage
return coverage;
}
unsigned int get_coverage_binary (hb_codepoint_t glyph_id,
hb_ot_layout_binary_cache_t *cache) const
{
unsigned coverage;
if (cache && cache->get (glyph_id, &coverage)) return coverage < cache->MAX_VALUE ? coverage : NOT_COVERED;
coverage = get_coverage (glyph_id);
if (cache) {
if (coverage == NOT_COVERED)
cache->set_unchecked (glyph_id, cache->MAX_VALUE);
else
cache->set_unchecked (glyph_id, 0);
}
return coverage;
}
unsigned get_population () const
{
switch (u.format.v) {
+3
View File
@@ -32,6 +32,9 @@
using hb_ot_layout_mapping_cache_t = hb_cache_t<15, 8, 7>;
static_assert (sizeof (hb_ot_layout_mapping_cache_t) == 256, "");
using hb_ot_layout_binary_cache_t = hb_cache_t<14, 1, 7>;
static_assert (sizeof (hb_ot_layout_binary_cache_t) == 128, "");
namespace OT {
namespace Layout {
+10 -6
View File
@@ -64,12 +64,16 @@ template <unsigned int key_bits=16,
struct hb_cache_t
{
using item_t = typename std::conditional<thread_safe,
typename std::conditional<key_bits + value_bits - cache_bits <= 16,
hb_atomic_t<unsigned short>,
hb_atomic_t<unsigned int>>::type,
typename std::conditional<key_bits + value_bits - cache_bits <= 16,
unsigned short,
unsigned int>::type
typename std::conditional<key_bits + value_bits - cache_bits <= 8,
hb_atomic_t<unsigned char>,
typename std::conditional<key_bits + value_bits - cache_bits <= 16,
hb_atomic_t<unsigned short>,
hb_atomic_t<unsigned int>>::type>::type,
typename std::conditional<key_bits + value_bits - cache_bits <= 8,
unsigned char,
typename std::conditional<key_bits + value_bits - cache_bits <= 16,
unsigned short,
unsigned int>::type>::type
>::type;
static_assert ((key_bits >= cache_bits), "");
+4 -4
View File
@@ -2710,7 +2710,7 @@ struct ContextFormat2_5
struct external_cache_t
{
hb_ot_layout_mapping_cache_t coverage;
hb_ot_layout_binary_cache_t coverage;
};
void *external_cache_create () const
{
@@ -2728,7 +2728,7 @@ struct ContextFormat2_5
TRACE_APPLY (this);
#ifndef HB_NO_OT_LAYOUT_LOOKUP_CACHE
external_cache_t *cache = (external_cache_t *) external_cache;
unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint, cache ? &cache->coverage : nullptr);
unsigned int index = (this+coverage).get_coverage_binary (c->buffer->cur().codepoint, cache ? &cache->coverage : nullptr);
#else
unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint);
#endif
@@ -3951,7 +3951,7 @@ struct ChainContextFormat2_5
struct external_cache_t
{
hb_ot_layout_mapping_cache_t coverage;
hb_ot_layout_binary_cache_t coverage;
};
void *external_cache_create () const
{
@@ -3969,7 +3969,7 @@ struct ChainContextFormat2_5
TRACE_APPLY (this);
#ifndef HB_NO_OT_LAYOUT_LOOKUP_CACHE
external_cache_t *cache = (external_cache_t *) external_cache;
unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint, cache ? &cache->coverage : nullptr);
unsigned int index = (this+coverage).get_coverage_binary (c->buffer->cur().codepoint, cache ? &cache->coverage : nullptr);
#else
unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint);
#endif