From 5be62a9f66b0964854e972f9ec36ffc0e3374a60 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 5 Feb 2025 19:30:01 +0000 Subject: [PATCH] [PairPosFormat1] Use a coverage cache as well Speeds up Arial shaping by 3%. --- src/OT/Layout/GPOS/PairPosFormat1.hh | 43 ++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/src/OT/Layout/GPOS/PairPosFormat1.hh b/src/OT/Layout/GPOS/PairPosFormat1.hh index ac2774a76..c9a3de426 100644 --- a/src/OT/Layout/GPOS/PairPosFormat1.hh +++ b/src/OT/Layout/GPOS/PairPosFormat1.hh @@ -103,11 +103,50 @@ struct PairPosFormat1_3 const Coverage &get_coverage () const { return this+coverage; } - bool apply (hb_ot_apply_context_t *c) const + unsigned cache_cost () const + { + return (this+coverage).cost (); + } + static void * cache_func (void *p, hb_ot_lookup_cache_op_t op) + { + switch (op) + { + case hb_ot_lookup_cache_op_t::CREATE: + { + hb_ot_lookup_cache_t *cache = (hb_ot_lookup_cache_t *) hb_malloc (sizeof (hb_ot_lookup_cache_t)); + if (likely (cache)) + cache->clear (); + return cache; + } + case hb_ot_lookup_cache_op_t::ENTER: + return (void *) true; + case hb_ot_lookup_cache_op_t::LEAVE: + return nullptr; + case hb_ot_lookup_cache_op_t::DESTROY: + { + hb_ot_lookup_cache_t *cache = (hb_ot_lookup_cache_t *) p; + hb_free (cache); + return nullptr; + } + } + } + + bool apply_cached (hb_ot_apply_context_t *c) const { return _apply (c, true); } + bool apply (hb_ot_apply_context_t *c) const { return _apply (c, false); } + bool _apply (hb_ot_apply_context_t *c, bool cached) const { TRACE_APPLY (this); + +#ifndef HB_NO_OT_LAYOUT_LOOKUP_CACHE + hb_ot_lookup_cache_t *cache = cached ? (hb_ot_lookup_cache_t *) c->lookup_accel->cache : nullptr; +#endif + hb_buffer_t *buffer = c->buffer; +#ifndef HB_NO_OT_LAYOUT_LOOKUP_CACHE + unsigned int index = (this+coverage).get_coverage (buffer->cur().codepoint, cache); +#else unsigned int index = (this+coverage).get_coverage (buffer->cur().codepoint); +#endif if (likely (index == NOT_COVERED)) return_trace (false); hb_ot_apply_context_t::skipping_iterator_t &skippy_iter = c->iter_input; @@ -156,7 +195,7 @@ struct PairPosFormat1_3 strip = true; newFormats = compute_effective_value_formats (glyphset, strip, true); } - + out->valueFormat[0] = newFormats.first; out->valueFormat[1] = newFormats.second;