diff --git a/src/hb-algs.hh b/src/hb-algs.hh index a10e82e9e..44104715c 100644 --- a/src/hb-algs.hh +++ b/src/hb-algs.hh @@ -765,30 +765,44 @@ hb_codepoint_parse (const char *s, unsigned int len, int base, hb_codepoint_t *o } -struct HbOpOr +struct hb_bitwise_or { static constexpr bool passthru_left = true; static constexpr bool passthru_right = true; - template static void process (T &o, const T &a, const T &b) { o = a | b; } -}; -struct HbOpAnd + template + auto operator () (const T &a, const T &b) const HB_AUTO_RETURN (a | b) +} +HB_FUNCOBJ (hb_bitwise_or); +struct hb_bitwise_and { static constexpr bool passthru_left = false; static constexpr bool passthru_right = false; - template static void process (T &o, const T &a, const T &b) { o = a & b; } -}; -struct HbOpMinus -{ - static constexpr bool passthru_left = true; - static constexpr bool passthru_right = false; - template static void process (T &o, const T &a, const T &b) { o = a & ~b; } -}; -struct HbOpXor + template + auto operator () (const T &a, const T &b) const HB_AUTO_RETURN (a & b) +} +HB_FUNCOBJ (hb_bitwise_and); +struct hb_bitwise_xor { static constexpr bool passthru_left = true; static constexpr bool passthru_right = true; - template static void process (T &o, const T &a, const T &b) { o = a ^ b; } -}; + template + auto operator () (const T &a, const T &b) const HB_AUTO_RETURN (a ^ b) +} +HB_FUNCOBJ (hb_bitwise_xor); +struct hb_bitwise_sub +{ + static constexpr bool passthru_left = true; + static constexpr bool passthru_right = false; + template + auto operator () (const T &a, const T &b) const HB_AUTO_RETURN (a & ~b) +} +HB_FUNCOBJ (hb_bitwise_sub); +struct hb_bitwise_neg +{ + template + auto operator () (const T &a) const HB_AUTO_RETURN (~a) +} +HB_FUNCOBJ (hb_bitwise_neg); /* Compiler-assisted vectorization. */ @@ -804,26 +818,26 @@ struct hb_vector_size_t void clear (unsigned char v = 0) { memset (this, v, sizeof (*this)); } - template - hb_vector_size_t process (const hb_vector_size_t &o) const + template + hb_vector_size_t process (const Op& op, const hb_vector_size_t &o) const { hb_vector_size_t r; #if HB_VECTOR_SIZE if (HB_VECTOR_SIZE && 0 == (byte_size * 8) % HB_VECTOR_SIZE) for (unsigned int i = 0; i < ARRAY_LENGTH (u.vec); i++) - Op::process (r.u.vec[i], u.vec[i], o.u.vec[i]); + r.u.vec[i] = op (u.vec[i], o.u.vec[i]); else #endif for (unsigned int i = 0; i < ARRAY_LENGTH (u.v); i++) - Op::process (r.u.v[i], u.v[i], o.u.v[i]); + r.u.v[i] = op (u.v[i], o.u.v[i]); return r; } hb_vector_size_t operator | (const hb_vector_size_t &o) const - { return process (o); } + { return process (hb_bitwise_or, o); } hb_vector_size_t operator & (const hb_vector_size_t &o) const - { return process (o); } + { return process (hb_bitwise_and, o); } hb_vector_size_t operator ^ (const hb_vector_size_t &o) const - { return process (o); } + { return process (hb_bitwise_xor, o); } hb_vector_size_t operator ~ () const { hb_vector_size_t r; diff --git a/src/hb-set.hh b/src/hb-set.hh index 332e07bd0..3b30fa4d4 100644 --- a/src/hb-set.hh +++ b/src/hb-set.hh @@ -440,8 +440,8 @@ struct hb_set_t return true; } - template - void process (const hb_set_t *other) + template + void process (const Op& op, const hb_set_t *other) { if (unlikely (!successful)) return; @@ -495,7 +495,7 @@ struct hb_set_t b--; count--; page_map[count] = page_map[a]; - Op::process (page_at (count).v, page_at (a).v, other->page_at (b).v); + page_at (count).v = op (page_at (a).v, other->page_at (b).v); } else if (page_map[a - 1].major > other->page_map[b - 1].major) { @@ -541,19 +541,19 @@ struct hb_set_t void union_ (const hb_set_t *other) { - process (other); + process (hb_bitwise_or, other); } void intersect (const hb_set_t *other) { - process (other); + process (hb_bitwise_and, other); } void subtract (const hb_set_t *other) { - process (other); + process (hb_bitwise_sub, other); } void symmetric_difference (const hb_set_t *other) { - process (other); + process (hb_bitwise_xor, other); } bool next (hb_codepoint_t *codepoint) const {