This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] libstdc++/8645


Hi all,

I have analyzed in detail the logic underlying this PR and came to
the conclusion that submitter is right.

Lines 446-471 (and, similarly, 484-508) of stl_tree.h are of this
form:

         if ((!A || B) && C)
           {
             //
           }
         else
           {
             if (C)
               {
                 if (A) __w->_M_left->_M_color = _M_black;
                 //
               }
             //
           }

Therefore, the check for A (_w->_M_left, that is) in the innermost if
is definitely redundant.

Patch follows, tested x86-linux.

Ciao, Paolo.

///////////
2002-11-22  Laszlo Ersek  <erseklaszlo@chello.hu>
	    Paolo Carlini  <pcarlini@unitus.it>

	PR libstdc++/8645
	* include/bits/stl_tree.h (_Rb_tree_rebalance_for_erase):
	Don't check that __w->_M_left != 0 and __w->_M_right != 0
	when they can't be otherwise.
--- stl_tree.h.~1.16.~	2002-09-11 01:19:10.000000000 +0200
+++ stl_tree.h	2002-11-22 14:42:13.000000000 +0100
@@ -457,7 +457,7 @@
 		  if (__w->_M_right == 0 
 		      || __w->_M_right->_M_color == _M_black) 
 		    {
-		      if (__w->_M_left) __w->_M_left->_M_color = _M_black;
+		      __w->_M_left->_M_color = _M_black;
 		      __w->_M_color = _M_red;
 		      _Rb_tree_rotate_right(__w, __root);
 		      __w = __x_parent->_M_right;
@@ -494,7 +494,7 @@
 		{
 		  if (__w->_M_left == 0 || __w->_M_left->_M_color == _M_black) 
 		    {
-		      if (__w->_M_right) __w->_M_right->_M_color = _M_black;
+		      __w->_M_right->_M_color = _M_black;
 		      __w->_M_color = _M_red;
 		      _Rb_tree_rotate_left(__w, __root);
 		      __w = __x_parent->_M_left;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]