return-value policy question
Nathan Myers
ncm-nospam@cantrip.org
Tue Apr 29 05:26:00 GMT 2003
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@cantrip.org
More information about the Libstdc++
mailing list