[bit-set-invertible] Rewrite next/previous_range() in terms of s.next/previous()

This commit is contained in:
Behdad Esfahbod 2021-08-19 11:24:17 -06:00
parent eb98bc1e32
commit b21038d91d
1 changed files with 8 additions and 18 deletions

View File

@ -230,20 +230,15 @@ struct hb_bit_set_invertible_t
if (likely (!inverted)) if (likely (!inverted))
return s.next_range (first, last); return s.next_range (first, last);
hb_codepoint_t i; if (!next (last))
i = *last;
if (!next (&i))
{ {
*last = *first = INVALID; *last = *first = INVALID;
return false; return false;
} }
/* TODO Speed up. */ *first = *last;
*last = *first = i; s.next (last);
while (next (&i) && i == *last + 1) --*last;
(*last)++;
return true; return true;
} }
bool previous_range (hb_codepoint_t *first, hb_codepoint_t *last) const bool previous_range (hb_codepoint_t *first, hb_codepoint_t *last) const
@ -251,20 +246,15 @@ struct hb_bit_set_invertible_t
if (likely (!inverted)) if (likely (!inverted))
return s.previous_range (first, last); return s.previous_range (first, last);
hb_codepoint_t i; if (!previous (first))
i = *first;
if (!previous (&i))
{ {
*last = *first = INVALID; *last = *first = INVALID;
return false; return false;
} }
/* TODO Speed up. */ *last = *first;
*last = *first = i; s.previous (first);
while (previous (&i) && i == *first - 1) ++*first;
(*first)--;
return true; return true;
} }