diff --git a/src/hb-algs.hh b/src/hb-algs.hh index 716caf866..c2e99c1fc 100644 --- a/src/hb-algs.hh +++ b/src/hb-algs.hh @@ -1178,11 +1178,35 @@ struct } HB_FUNCOBJ (hb_bitwise_xor); struct +{ HB_PARTIALIZE(2); + template constexpr auto + operator () (const T &a, const T &b) const HB_AUTO_RETURN (~a & b) +} +HB_FUNCOBJ (hb_bitwise_lt); +struct { HB_PARTIALIZE(2); template constexpr auto operator () (const T &a, const T &b) const HB_AUTO_RETURN (a & ~b) } -HB_FUNCOBJ (hb_bitwise_sub); +HB_FUNCOBJ (hb_bitwise_gt); // aka sub +struct +{ HB_PARTIALIZE(2); + template constexpr auto + operator () (const T &a, const T &b) const HB_AUTO_RETURN (~a & ~b) +} +HB_FUNCOBJ (hb_bitwise_non); +struct +{ HB_PARTIALIZE(2); + template constexpr auto + operator () (const T &a, const T &b) const HB_AUTO_RETURN (~a | b) +} +HB_FUNCOBJ (hb_bitwise_le); +struct +{ HB_PARTIALIZE(2); + template constexpr auto + operator () (const T &a, const T &b) const HB_AUTO_RETURN (a | ~b) +} +HB_FUNCOBJ (hb_bitwise_ge); struct { template constexpr auto @@ -1203,6 +1227,12 @@ struct } HB_FUNCOBJ (hb_sub); struct +{ HB_PARTIALIZE(2); + template constexpr auto + operator () (const T &a, const T2 &b) const HB_AUTO_RETURN (b - a) +} +HB_FUNCOBJ (hb_rsub); +struct { HB_PARTIALIZE(2); template constexpr auto operator () (const T &a, const T2 &b) const HB_AUTO_RETURN (a * b) diff --git a/src/hb-bit-set-invertible.hh b/src/hb-bit-set-invertible.hh index 5d1c9f566..22a4c4f29 100644 --- a/src/hb-bit-set-invertible.hh +++ b/src/hb-bit-set-invertible.hh @@ -108,18 +108,69 @@ struct hb_bit_set_invertible_t return inverted ? larger_set.s.is_subset (s) : s.is_subset (larger_set.s); } + protected: template void process (const Op& op, const hb_bit_set_invertible_t &other) - { s.process (op, other.s); } - - /*XXX(inverted)*/ - void union_ (const hb_bit_set_invertible_t &other) { process (hb_bitwise_or, other); } - /*XXX(inverted)*/ - void intersect (const hb_bit_set_invertible_t &other) { process (hb_bitwise_and, other); } - /*XXX(inverted)*/ - void subtract (const hb_bit_set_invertible_t &other) { process (hb_bitwise_sub, other); } - /*XXX(inverted)*/ - void symmetric_difference (const hb_bit_set_invertible_t &other) { process (hb_bitwise_xor, other); } + { + s.process (op, other.s); + inverted = bool (op (int (inverted), int (other.inverted))); + } + public: + void union_ (const hb_bit_set_invertible_t &other) + { + if (inverted == other.inverted) + { + if (inverted) + process (hb_bitwise_and, other); + else + process (hb_bitwise_or, other); /* Main branch. */ + } + else + { + if (inverted) + process (hb_bitwise_gt, other); + else + process (hb_bitwise_lt, other); + } + } + void intersect (const hb_bit_set_invertible_t &other) + { + if (inverted == other.inverted) + { + if (inverted) + process (hb_bitwise_or, other); + else + process (hb_bitwise_and, other); /* Main branch. */ + } + else + { + if (inverted) + process (hb_bitwise_ge, other); + else + process (hb_bitwise_le, other); + } + } + void subtract (const hb_bit_set_invertible_t &other) + { + if (inverted == other.inverted) + { + if (inverted) + process (hb_bitwise_lt, other); + else + process (hb_bitwise_gt, other); /* Main branch. */ + } + else + { + if (inverted) + process (hb_bitwise_non, other); + else + process (hb_bitwise_and, other); + } + } + void symmetric_difference (const hb_bit_set_invertible_t &other) + { + process (hb_bitwise_xor, other); + } bool next (hb_codepoint_t *codepoint) const { diff --git a/src/hb-bit-set.hh b/src/hb-bit-set.hh index 5f38f4eaf..065b85f1b 100644 --- a/src/hb-bit-set.hh +++ b/src/hb-bit-set.hh @@ -577,7 +577,7 @@ struct hb_bit_set_t void union_ (const hb_bit_set_t &other) { process (hb_bitwise_or, other); } void intersect (const hb_bit_set_t &other) { process (hb_bitwise_and, other); } - void subtract (const hb_bit_set_t &other) { process (hb_bitwise_sub, other); } + void subtract (const hb_bit_set_t &other) { process (hb_bitwise_gt, other); } void symmetric_difference (const hb_bit_set_t &other) { process (hb_bitwise_xor, other); } bool next (hb_codepoint_t *codepoint) const