__black_count inlining fix

Nick Rasmussen nick@jive.org
Sat Jul 3 04:06:00 GMT 1999


If the default argument is a bit too cute, you can do this same trick by
making a __black_count_aux function that takes three arguments (but g++
doesn't do as good of a job optimizing it away).

patch is against the head of gcc-2_95-branch.

-nick

Index: ChangeLog
===================================================================
RCS file: /cvs/egcs/egcs/libstdc++/stl/ChangeLog,v
retrieving revision 1.26.4.2
diff -c -3 -p -r1.26.4.2 ChangeLog
*** ChangeLog	1999/06/18 00:00:10	1.26.4.2
--- ChangeLog	1999/07/03 11:00:58
***************
*** 1,3 ****
--- 1,7 ----
+ 1999-07-03  Nick Rasmussen  <nick@jive.org>
+ 
+ 	* stl_tree.h: Changed __black_count to allow inlining.
+ 
  1999-06-18  Martin von Löwis  <loewis@informatik.hu-berlin.de>
  
  	* stl_queue.h: Rename _M_c to c, and _M_comp to comp.
Index: stl_tree.h
===================================================================
RCS file: /cvs/egcs/egcs/libstdc++/stl/stl_tree.h,v
retrieving revision 1.2
diff -c -3 -p -r1.2 stl_tree.h
*** stl_tree.h	1998/09/02 17:25:11	1.2
--- stl_tree.h	1999/07/03 11:00:59
*************** _Rb_tree<_Key, _Value, _KoV, _Compare, _
*** 1253,1269 ****
                                               upper_bound(__k));
  }
  
! inline int 
! __black_count(_Rb_tree_node_base* __node, _Rb_tree_node_base* __root)
  {
    if (__node == 0)
!     return 0;
    else {
!     int __bc = __node->_M_color == _S_rb_tree_black ? 1 : 0;
      if (__node == __root)
        return __bc;
      else
!       return __bc + __black_count(__node->_M_parent, __root);
    }
  }
  
--- 1253,1270 ----
                                               upper_bound(__k));
  }
  
! inline int
! __black_count(_Rb_tree_node_base* __node, _Rb_tree_node_base* __root,
!               int __bc = 0)
  {
    if (__node == 0)
!     return __bc;
    else {
!     __bc += __node->_M_color == _S_rb_tree_black ? 1 : 0;
      if (__node == __root)
        return __bc;
      else
!       return __black_count(__node->_M_parent, __root, __bc);
    }
  }
  


More information about the Gcc-patches mailing list