Speed up ValueFormat len() calc

This commit is contained in:
Behdad Esfahbod committed 2025-09-23 20:34:13 -06:00
1 parent 88dfa2abd3
commit d350cb833a
2 files changed
+12 -1

No files matched your search

+1 -1
View File
@@ -58,7 +58,7 @@ struct ValueFormat : HBUINT16
NumType& operator = (uint16_t i) { v = i; return *this; }
unsigned int get_len () const { return hb_popcount ((unsigned int) *this); }
unsigned int get_len () const { return hb_popcount8 ((unsigned int) *this); }
unsigned int get_size () const { return get_len () * Value::static_size; }
hb_vector_t<unsigned> get_device_table_indices () const {
+11
View File
@@ -854,6 +854,17 @@ HB_FUNCOBJ (hb_clamp);
* Bithacks.
*/
/* Return the number of 1 bits in a uint8_t; faster than hb_popcount() */
static inline unsigned
hb_popcount8 (unsigned v)
{
static const uint8_t popcount4[16] = {
0, 1, 1, 2, 1, 2, 2, 3,
1, 2, 2, 3, 2, 3, 3, 4
};
return popcount4[v & 0xF] + popcount4[v >> 4];
}
/* Return the number of 1 bits in v. */
template <typename T>
static inline unsigned int