Massage mask setting a bit more

Still finding the exact correct way the masks should be set.
diff --git a/src/hb-buffer-private.hh b/src/hb-buffer-private.hh
index 8154b17..585a82a 100644
--- a/src/hb-buffer-private.hh
+++ b/src/hb-buffer-private.hh
@@ -107,6 +107,10 @@
 
 HB_INTERNAL void
 _hb_buffer_add_masks (hb_buffer_t *buffer,
+		      hb_mask_t    mask);
+
+HB_INTERNAL void
+_hb_buffer_set_masks (hb_buffer_t *buffer,
 		      hb_mask_t    value,
 		      hb_mask_t    mask,
 		      unsigned int cluster_start,
@@ -165,12 +169,21 @@
   { _hb_buffer_add_output_glyph (this, glyph_index, component, ligID); }
   inline void replace_glyph (hb_codepoint_t glyph_index) { add_output_glyph (glyph_index); }
 
-  inline void reset_masks (hb_mask_t mask) { _hb_buffer_reset_masks (this, mask); }
-  inline void add_masks (hb_mask_t value,
+  inline void reset_masks (hb_mask_t mask)
+  {
+    for (unsigned int i = 0; i < len; i++)
+      info[i].mask = mask;
+  }
+  inline void add_masks (hb_mask_t mask)
+  {
+    for (unsigned int i = 0; i < len; i++)
+      info[i].mask |= mask;
+  }
+  inline void set_masks (hb_mask_t value,
 			 hb_mask_t mask,
 			 unsigned int cluster_start,
 			 unsigned int cluster_end)
-  { _hb_buffer_add_masks (this, value, mask, cluster_start, cluster_end); }
+  { _hb_buffer_set_masks (this, value, mask, cluster_start, cluster_end); }
 
 };
 
diff --git a/src/hb-buffer.cc b/src/hb-buffer.cc
index c6bceeb..930f380 100644
--- a/src/hb-buffer.cc
+++ b/src/hb-buffer.cc
@@ -470,6 +470,15 @@
 
 void
 _hb_buffer_add_masks (hb_buffer_t *buffer,
+		      hb_mask_t    mask)
+{
+  unsigned int count = buffer->len;
+  for (unsigned int i = 0; i < count; i++)
+    buffer->info[i].mask |= mask;
+}
+
+void
+_hb_buffer_set_masks (hb_buffer_t *buffer,
 		      hb_mask_t    value,
 		      hb_mask_t    mask,
 		      unsigned int cluster_start,
diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc
index ee5f796..7b4a451 100644
--- a/src/hb-ot-shape.cc
+++ b/src/hb-ot-shape.cc
@@ -88,13 +88,15 @@
 
   hb_ot_shape_complex_setup_masks (c);
 
+  c->buffer->reset_masks (global_mask);
+
   for (unsigned int i = 0; i < c->num_user_features; i++)
   {
     const hb_feature_t *feature = &c->user_features[i];
     if (!(feature->start == 0 && feature->end == (unsigned int)-1)) {
       unsigned int shift;
       hb_mask_t mask = c->plan->map.get_mask (feature->tag, &shift);
-      c->buffer->add_masks (feature->value << shift, mask, feature->start, feature->end);
+      c->buffer->set_masks (feature->value << shift, mask, feature->start, feature->end);
     }
   }
 }
@@ -180,7 +182,7 @@
   for (unsigned int i = 0; i < count; i++) {
     hb_codepoint_t codepoint = get_mirroring (c->buffer->info[i].codepoint);
     if (likely (codepoint == c->buffer->info[i].codepoint))
-      c->buffer->info[i].mask |= rtlm_mask;
+      c->buffer->info[i].mask |= rtlm_mask; /* XXX this should be moved to before setting user-feature masks */
     else
       c->buffer->info[i].codepoint = codepoint;
   }