This is the mail archive of the mailing list for the libstdc++ project. See the libstdc++ home page for more information.

[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index] [Subject Index] [Author Index] [Thread Index]

re: recursive inlines in stl_tree

> Benjamin wrote:
> I suspect this is declared inline because either the SGI compiler is
> capable of inlining it, or a general typo. I haven't checked to verify
> the SGI compiler behavior: out of curiosity, is anyone using a
> compiler that does? G++ is not able to inline this, and it would seem
> to make sense to me to remove it, as per your suggestion.

G++ *should* be able to inline it.  It's tail-recursive,
so is easily turned into a loop.  (This is stl/bits/stl_tree.h,
function __black_count().)

If we can't get g++ to inline it as is, we should go ahead and
manually turn it into a loop ourselves.  Something like

  __sum += (__node->_M_color == _S_rb_tree_black) ? 1 : 0;
  return (__node == __root) ?
    __sum : __black_count(__node->_M_parent, __root, __sum);
  do {
    __sum += (__node->_M_color == _S_rb_tree_black) ? 1 : 0;
    if (__node == __root) break;
    __node = __node->_M_parent;
  } while (1);
  return __sum;

And, of course, put the inline back in.

In that case there's no need for the __sum argument; it could 
be a local variable instead, though that shouldn't make any 
difference if the function actually gets inlined.

Nathan Myers