summaryrefslogtreecommitdiff
path: root/gtk/gtkallocatedbitmask.c
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2015-09-07 14:31:26 +0200
committerBenjamin Otte <otte@redhat.com>2015-09-07 14:32:09 +0200
commitc8c666c87c827323a128264ecf1943f8107713f9 (patch)
treea080485793252b78e45994bad21e85863bda4d7c /gtk/gtkallocatedbitmask.c
parentf5fe1e3a06b6ea9160f9b05aaadd228a813bafb9 (diff)
downloadgtk+-c8c666c87c827323a128264ecf1943f8107713f9.tar.gz
bitmask: Fix broken invert_range() implementation
The speed-up in 7da1f8a1ce145f48b6299fd8be86a64389ff0b0d was wrong in certain conditions, even though it didn't trigger the existing testsuite. New testcase /bitmask/invert_range_hardcoded included.
Diffstat (limited to 'gtk/gtkallocatedbitmask.c')
-rw-r--r--gtk/gtkallocatedbitmask.c18
1 files changed, 6 insertions, 12 deletions
diff --git a/gtk/gtkallocatedbitmask.c b/gtk/gtkallocatedbitmask.c
index 0f4a8d9e6d..7414b1994c 100644
--- a/gtk/gtkallocatedbitmask.c
+++ b/gtk/gtkallocatedbitmask.c
@@ -25,7 +25,7 @@
#define VALUE_SIZE_BITS (sizeof (VALUE_TYPE) * 8)
#define VALUE_BIT(idx) (((VALUE_TYPE) 1) << (idx))
-#define ALL_BITS G_MAXSIZE
+#define ALL_BITS (~((VALUE_TYPE) 0))
struct _GtkBitmask {
gsize len;
@@ -301,17 +301,11 @@ _gtk_allocated_bitmask_invert_range (GtkBitmask *mask,
if (end_word >= mask->len)
mask = gtk_allocated_bitmask_resize (mask, end_word + 1);
- if (start_word == end_word)
- {
- mask->data[start_word] ^= (ALL_BITS >> (end_bit - start_bit)) << start_bit;
- }
- else
- {
- mask->data[start_word] ^= ALL_BITS << start_bit;
- for (i = start_word + 1; i < end_word; i++)
- mask->data[i] ^= ALL_BITS;
- mask->data[end_word] ^= ALL_BITS >> (VALUE_SIZE_BITS - end_bit);
- }
+ for (i = start_word; i <= end_word; i++)
+ mask->data[i] ^= ALL_BITS;
+ mask->data[start_word] ^= (((VALUE_TYPE) 1) << start_bit) - 1;
+ if (end_bit != 63)
+ mask->data[end_word] ^= ALL_BITS << (end_bit + 1);
return gtk_allocated_bitmask_shrink (mask);
}