Add per-subtable set-digests

This speeds up Roboto shaping by ~10%.  I was hoping for more.
Still, good defense against lookups with many subtables.
This commit is contained in:
Behdad Esfahbod 2018-10-10 12:07:49 -04:00
parent e78549edfb
commit b3390990f5
2 changed files with 59 additions and 51 deletions

View File

@ -36,7 +36,7 @@
/* Global nul-content Null pool. Enlarge as necessary. */ /* Global nul-content Null pool. Enlarge as necessary. */
#define HB_NULL_POOL_SIZE 512 #define HB_NULL_POOL_SIZE 1024
extern HB_INTERNAL extern HB_INTERNAL
hb_vector_size_impl_t const _hb_NullPool[(HB_NULL_POOL_SIZE + sizeof (hb_vector_size_impl_t) - 1) / sizeof (hb_vector_size_impl_t)]; hb_vector_size_impl_t const _hb_NullPool[(HB_NULL_POOL_SIZE + sizeof (hb_vector_size_impl_t) - 1) / sizeof (hb_vector_size_impl_t)];

View File

@ -259,56 +259,6 @@ struct hb_add_coverage_context_t :
}; };
struct hb_get_subtables_context_t :
hb_dispatch_context_t<hb_get_subtables_context_t, hb_void_t, HB_DEBUG_APPLY>
{
template <typename Type>
static inline bool apply_to (const void *obj, OT::hb_ot_apply_context_t *c)
{
const Type *typed_obj = (const Type *) obj;
return typed_obj->apply (c);
}
typedef bool (*hb_apply_func_t) (const void *obj, OT::hb_ot_apply_context_t *c);
struct hb_applicable_t
{
inline void init (const void *obj_, hb_apply_func_t apply_func_)
{
obj = obj_;
apply_func = apply_func_;
}
inline bool apply (OT::hb_ot_apply_context_t *c) const { return apply_func (obj, c); }
private:
const void *obj;
hb_apply_func_t apply_func;
};
typedef hb_vector_t<hb_applicable_t, 2> array_t;
/* Dispatch interface. */
inline const char *get_name (void) { return "GET_SUBTABLES"; }
template <typename T>
inline return_t dispatch (const T &obj)
{
hb_applicable_t *entry = array.push();
entry->init (&obj, apply_to<T>);
return HB_VOID;
}
static return_t default_return_value (void) { return HB_VOID; }
bool stop_sublookup_iteration (return_t r HB_UNUSED) const { return false; }
hb_get_subtables_context_t (array_t &array_) :
array (array_),
debug_depth (0) {}
array_t &array;
unsigned int debug_depth;
};
struct hb_ot_apply_context_t : struct hb_ot_apply_context_t :
hb_dispatch_context_t<hb_ot_apply_context_t, bool, HB_DEBUG_APPLY> hb_dispatch_context_t<hb_ot_apply_context_t, bool, HB_DEBUG_APPLY>
{ {
@ -671,6 +621,64 @@ struct hb_ot_apply_context_t :
}; };
struct hb_get_subtables_context_t :
hb_dispatch_context_t<hb_get_subtables_context_t, hb_void_t, HB_DEBUG_APPLY>
{
template <typename Type>
static inline bool apply_to (const void *obj, OT::hb_ot_apply_context_t *c)
{
const Type *typed_obj = (const Type *) obj;
return typed_obj->apply (c);
}
typedef bool (*hb_apply_func_t) (const void *obj, OT::hb_ot_apply_context_t *c);
struct hb_applicable_t
{
template <typename T>
inline void init (const T &obj_, hb_apply_func_t apply_func_)
{
obj = &obj_;
apply_func = apply_func_;
digest.init ();
obj_.get_coverage ().add_coverage (&digest);
}
inline bool apply (OT::hb_ot_apply_context_t *c) const
{
return digest.may_have (c->buffer->cur().codepoint) && apply_func (obj, c);
}
private:
const void *obj;
hb_apply_func_t apply_func;
hb_set_digest_t digest;
};
typedef hb_vector_t<hb_applicable_t, 2> array_t;
/* Dispatch interface. */
inline const char *get_name (void) { return "GET_SUBTABLES"; }
template <typename T>
inline return_t dispatch (const T &obj)
{
hb_applicable_t *entry = array.push();
entry->init (obj, apply_to<T>);
return HB_VOID;
}
static return_t default_return_value (void) { return HB_VOID; }
bool stop_sublookup_iteration (return_t r HB_UNUSED) const { return false; }
hb_get_subtables_context_t (array_t &array_) :
array (array_),
debug_depth (0) {}
array_t &array;
unsigned int debug_depth;
};
typedef bool (*intersects_func_t) (const hb_set_t *glyphs, const HBUINT16 &value, const void *data); typedef bool (*intersects_func_t) (const hb_set_t *glyphs, const HBUINT16 &value, const void *data);
typedef void (*collect_glyphs_func_t) (hb_set_t *glyphs, const HBUINT16 &value, const void *data); typedef void (*collect_glyphs_func_t) (hb_set_t *glyphs, const HBUINT16 &value, const void *data);