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]

return-value policy question


In much of the library implementation I find code like that in
streambuf::sputc :

      int_type __ret;
      if (_M_out_cur < _M_out_end)
        {
          *_M_out_cur = __c;
          _M_move_out_cur(1);
          __ret = traits_type::to_int_type(__c);
        }
      else
        __ret = this->overflow(traits_type::to_int_type(__c));
      return __ret;

instead of the simpler and more elegant

      if (_M_out_cur < _M_out_end)
        {
          *_M_out_cur = __c;
          _M_move_out_cur(1);
          return traits_type::to_int_type(__c);
        }
      return this->overflow(traits_type::to_int_type(__c));

or the even simpler and more traditional

      return (_M_out_cur < _M_out_end) ?
        traits_type::to_int_type(*_M_out_cur++ = __c) :
        this->overflow(traits_type::to_int_type(__c));

Is there some objective reason to prefer assigning a variable and 
sharing the "return" statement, over just returning when it's time?  
Is it a leftover optimization?  Was it ever optimal?  Is it now?

Nathan Myers
ncm-nospam at cantrip dot org


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