提交 c4aa10eb 编写于 作者: B Behdad Esfahbod

Use constexpr to replace passthru_ bools

上级 2e48fd07
...@@ -915,32 +915,24 @@ hb_codepoint_parse (const char *s, unsigned int len, int base, hb_codepoint_t *o ...@@ -915,32 +915,24 @@ hb_codepoint_parse (const char *s, unsigned int len, int base, hb_codepoint_t *o
struct hb_bitwise_and struct hb_bitwise_and
{ HB_PARTIALIZE(2); { HB_PARTIALIZE(2);
static constexpr bool passthru_left = false;
static constexpr bool passthru_right = false;
template <typename T> constexpr auto template <typename T> constexpr auto
operator () (const T &a, const T &b) const HB_AUTO_RETURN (a & b) operator () (const T &a, const T &b) const HB_AUTO_RETURN (a & b)
} }
HB_FUNCOBJ (hb_bitwise_and); HB_FUNCOBJ (hb_bitwise_and);
struct hb_bitwise_or struct hb_bitwise_or
{ HB_PARTIALIZE(2); { HB_PARTIALIZE(2);
static constexpr bool passthru_left = true;
static constexpr bool passthru_right = true;
template <typename T> constexpr auto template <typename T> constexpr auto
operator () (const T &a, const T &b) const HB_AUTO_RETURN (a | b) operator () (const T &a, const T &b) const HB_AUTO_RETURN (a | b)
} }
HB_FUNCOBJ (hb_bitwise_or); HB_FUNCOBJ (hb_bitwise_or);
struct hb_bitwise_xor struct hb_bitwise_xor
{ HB_PARTIALIZE(2); { HB_PARTIALIZE(2);
static constexpr bool passthru_left = true;
static constexpr bool passthru_right = true;
template <typename T> constexpr auto template <typename T> constexpr auto
operator () (const T &a, const T &b) const HB_AUTO_RETURN (a ^ b) operator () (const T &a, const T &b) const HB_AUTO_RETURN (a ^ b)
} }
HB_FUNCOBJ (hb_bitwise_xor); HB_FUNCOBJ (hb_bitwise_xor);
struct hb_bitwise_sub struct hb_bitwise_sub
{ HB_PARTIALIZE(2); { HB_PARTIALIZE(2);
static constexpr bool passthru_left = true;
static constexpr bool passthru_right = false;
template <typename T> constexpr auto template <typename T> constexpr auto
operator () (const T &a, const T &b) const HB_AUTO_RETURN (a & ~b) operator () (const T &a, const T &b) const HB_AUTO_RETURN (a & ~b)
} }
......
...@@ -448,6 +448,8 @@ struct hb_set_t ...@@ -448,6 +448,8 @@ struct hb_set_t
dirty (); dirty ();
constexpr bool passthru_left = op (0, 0) || op (1, 0);
constexpr bool passthru_right = op (0, 0) || op (0, 1);
unsigned int na = pages.length; unsigned int na = pages.length;
unsigned int nb = other->pages.length; unsigned int nb = other->pages.length;
unsigned int next_page = na; unsigned int next_page = na;
...@@ -464,20 +466,20 @@ struct hb_set_t ...@@ -464,20 +466,20 @@ struct hb_set_t
} }
else if (page_map[a].major < other->page_map[b].major) else if (page_map[a].major < other->page_map[b].major)
{ {
if (Op::passthru_left) if (passthru_left)
count++; count++;
a++; a++;
} }
else else
{ {
if (Op::passthru_right) if (passthru_right)
count++; count++;
b++; b++;
} }
} }
if (Op::passthru_left) if (passthru_left)
count += na - a; count += na - a;
if (Op::passthru_right) if (passthru_right)
count += nb - b; count += nb - b;
if (count > pages.length) if (count > pages.length)
...@@ -501,7 +503,7 @@ struct hb_set_t ...@@ -501,7 +503,7 @@ struct hb_set_t
else if (page_map[a - 1].major > other->page_map[b - 1].major) else if (page_map[a - 1].major > other->page_map[b - 1].major)
{ {
a--; a--;
if (Op::passthru_left) if (passthru_left)
{ {
count--; count--;
page_map[count] = page_map[a]; page_map[count] = page_map[a];
...@@ -510,7 +512,7 @@ struct hb_set_t ...@@ -510,7 +512,7 @@ struct hb_set_t
else else
{ {
b--; b--;
if (Op::passthru_right) if (passthru_right)
{ {
count--; count--;
page_map[count].major = other->page_map[b].major; page_map[count].major = other->page_map[b].major;
...@@ -519,14 +521,14 @@ struct hb_set_t ...@@ -519,14 +521,14 @@ struct hb_set_t
} }
} }
} }
if (Op::passthru_left) if (passthru_left)
while (a) while (a)
{ {
a--; a--;
count--; count--;
page_map[count] = page_map [a]; page_map[count] = page_map [a];
} }
if (Op::passthru_right) if (passthru_right)
while (b) while (b)
{ {
b--; b--;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册