Bug 1403444 - Abstract red-black-tree link field reference with a new macro. r?njn draft
authorMike Hommey <mh+mozilla@glandium.org>
Mon, 25 Sep 2017 07:03:37 +0900
changeset 670914 ac9f160e917609f288ef1f48cc934515411bb4c1
parent 670913 f7643086efb2a18859dddc80079a6df5dd25cf0e
child 670915 5bf0215b8da256146bdba2d31922edc6fc43a93b
push id81767
push userbmo:mh+mozilla@glandium.org
push dateWed, 27 Sep 2017 06:43:40 +0000
reviewersnjn
bugs1403444
milestone58.0a1
Bug 1403444 - Abstract red-black-tree link field reference with a new macro. r?njn While we're going in the opposite direction, moving away from macros, upcoming intermediate steps are going to "manually" expand macros, but later steps will require changing how the link field reference is done, and having it in a single location then will be more convenient.
memory/build/rb.h
--- a/memory/build/rb.h
+++ b/memory/build/rb.h
@@ -125,34 +125,40 @@ public:
 /* Root structure. */
 template <typename T>
 struct RedBlackTree
 {
   T* rbt_root;
   T rbt_nil;
 };
 
+#define rb_node_field(a_node, a_field) (a_node)->a_field
+
 /* Left accessors. */
-#define rbp_left_get(a_type, a_field, a_node) (a_node)->a_field.Left()
+#define rbp_left_get(a_type, a_field, a_node)                                  \
+  rb_node_field(a_node, a_field).Left()
 #define rbp_left_set(a_type, a_field, a_node, a_left)                          \
-  (a_node)->a_field.SetLeft(a_left)
+  rb_node_field(a_node, a_field).SetLeft(a_left)
 
 /* Right accessors. */
-#define rbp_right_get(a_type, a_field, a_node) (a_node)->a_field.Right()
+#define rbp_right_get(a_type, a_field, a_node)                                 \
+  rb_node_field(a_node, a_field).Right()
 #define rbp_right_set(a_type, a_field, a_node, a_right)                        \
-  (a_node)->a_field.SetRight(a_right)
+  rb_node_field(a_node, a_field).SetRight(a_right)
 
 /* Color accessors. */
-#define rbp_red_get(a_type, a_field, a_node) (a_node)->a_field.IsRed()
+#define rbp_red_get(a_type, a_field, a_node)                                   \
+  rb_node_field(a_node, a_field).IsRed()
 #define rbp_color_set(a_type, a_field, a_node, a_red)                          \
-  (a_node)->a_field.SetColor(a_red ? NodeColor::Red : NodeColor::Black)
+  rb_node_field(a_node, a_field)                                               \
+    .SetColor(a_red ? NodeColor::Red : NodeColor::Black)
 #define rbp_red_set(a_type, a_field, a_node)                                   \
-  (a_node)->a_field.SetColor(NodeColor::Red)
+  rb_node_field(a_node, a_field).SetColor(NodeColor::Red)
 #define rbp_black_set(a_type, a_field, a_node)                                 \
-  (a_node)->a_field.SetColor(NodeColor::Black)
+  rb_node_field(a_node, a_field).SetColor(NodeColor::Black)
 
 /* Node initializer. */
 #define rbp_node_new(a_type, a_field, a_tree, a_node)                          \
   do {                                                                         \
     rbp_left_set(a_type, a_field, (a_node), &(a_tree)->rbt_nil);               \
     rbp_right_set(a_type, a_field, (a_node), &(a_tree)->rbt_nil);              \
     rbp_red_set(a_type, a_field, (a_node));                                    \
   } while (0)