Protect sets in-error from further modication

Fixes test-set.c
This commit is contained in:
Behdad Esfahbod 2013-01-02 23:02:59 -06:00
parent 8165f2765b
commit 7b1b720a8d

View File

@ -146,6 +146,9 @@ struct hb_set_t
inline void fini (void) {
}
inline void clear (void) {
if (unlikely (hb_object_is_inert (this)))
return;
in_error = false;
memset (elts, 0, sizeof elts);
}
inline bool is_empty (void) const {
@ -156,23 +159,27 @@ struct hb_set_t
}
inline void add (hb_codepoint_t g)
{
if (unlikely (in_error)) return;
if (unlikely (g == SENTINEL)) return;
if (unlikely (g > MAX_G)) return;
elt (g) |= mask (g);
}
inline void add_range (hb_codepoint_t a, hb_codepoint_t b)
{
if (unlikely (in_error)) return;
/* TODO Speedup */
for (unsigned int i = a; i < b + 1; i++)
add (i);
}
inline void del (hb_codepoint_t g)
{
if (unlikely (in_error)) return;
if (unlikely (g > MAX_G)) return;
elt (g) &= ~mask (g);
}
inline void del_range (hb_codepoint_t a, hb_codepoint_t b)
{
if (unlikely (in_error)) return;
/* TODO Speedup */
for (unsigned int i = a; i < b + 1; i++)
del (i);
@ -202,31 +209,37 @@ struct hb_set_t
}
inline void set (const hb_set_t *other)
{
if (unlikely (in_error)) return;
for (unsigned int i = 0; i < ELTS; i++)
elts[i] = other->elts[i];
}
inline void union_ (const hb_set_t *other)
{
if (unlikely (in_error)) return;
for (unsigned int i = 0; i < ELTS; i++)
elts[i] |= other->elts[i];
}
inline void intersect (const hb_set_t *other)
{
if (unlikely (in_error)) return;
for (unsigned int i = 0; i < ELTS; i++)
elts[i] &= other->elts[i];
}
inline void subtract (const hb_set_t *other)
{
if (unlikely (in_error)) return;
for (unsigned int i = 0; i < ELTS; i++)
elts[i] &= ~other->elts[i];
}
inline void symmetric_difference (const hb_set_t *other)
{
if (unlikely (in_error)) return;
for (unsigned int i = 0; i < ELTS; i++)
elts[i] ^= other->elts[i];
}
inline void invert (void)
{
if (unlikely (in_error)) return;
for (unsigned int i = 0; i < ELTS; i++)
elts[i] = ~elts[i];
}