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] Simplify a bit __copy_streambufs


Hi,

this all started with this simplification of the main 'if':

if (__in_avail != 0 && __sbin->_M_in_cur
&& __sbin->_M_in_cur + __in_avail <= __sbin->_M_in_end)


to

 if (__in_avail
     && __sbin->_M_in_end - __sbin->_M_in_cur >= __in_avail)

then, I noticed that basic_streambuf::showmanyc() just returns 0,
(and the overall structure of __copy_streambufs doesn't make
advantage of a possible non-trivial showmanyc() like that we
have for basic_filebuf) therefore __in_avail (i.e., in_avail())
its just _M_in_end - _M_in_cur. But, then, why call in_avail()
in the first place?
The other bits are trivial (nice ;) clean ups.

Tested x86-linux. Ok?

Paolo.

//////////
2003-04-24  Paolo Carlini  <pcarlini at unitus dot it>

	* include/bits/streambuf.tcc (__copy_streambufs): Don't
	use in_avail(), simplify.
diff -prN libstdc++-v3-orig/include/bits/streambuf.tcc libstdc++-v3/include/bits/streambuf.tcc
*** libstdc++-v3-orig/include/bits/streambuf.tcc	Tue Apr 22 19:32:25 2003
--- libstdc++-v3/include/bits/streambuf.tcc	Thu Apr 24 22:51:30 2003
*************** namespace std 
*** 188,217 ****
        typedef typename _Traits::off_type	off_type;
  
        streamsize __ret = 0;
-       streamsize __in_avail = __sbin->in_avail();
-       streamsize __xtrct;
        const off_type __buf_size =
  	__sbin->_M_buf_size > 0 ? __sbin->_M_buf_size : 1;
- 
        try 
  	{
! 	  while (__in_avail != -1)
    	    {
!  	      if (__in_avail != 0 && __sbin->_M_in_cur
! 		  && __sbin->_M_in_cur + __in_avail <= __sbin->_M_in_end) 
  		{
! 		  __xtrct = __sbout->sputn(__sbin->_M_in_cur, __in_avail);
  		  __ret += __xtrct;
  		  __sbin->_M_in_cur_move(__xtrct);
! 		  if (__xtrct != __in_avail)
  		    break;
  		}
   	      else 
  		{
  		  streamsize __charsread;
! 		  const streamsize __size =
! 		    std::min(__buf_size, off_type(__sbout->_M_out_end -
! 						  __sbout->_M_out_cur));
  		  if (__size > 1)
  		    {
  		      _CharT* __buf =
--- 188,216 ----
        typedef typename _Traits::off_type	off_type;
  
        streamsize __ret = 0;
        const off_type __buf_size =
  	__sbin->_M_buf_size > 0 ? __sbin->_M_buf_size : 1;
        try 
  	{
! 	  for (;;)
    	    {
! 	      streamsize __xtrct;
! 	      const off_type __avail = __sbin->_M_in_end
! 		                       - __sbin->_M_in_cur;
!  	      if (__avail)
  		{
! 		  __xtrct = __sbout->sputn(__sbin->_M_in_cur, __avail);
  		  __ret += __xtrct;
  		  __sbin->_M_in_cur_move(__xtrct);
! 		  if (__xtrct != __avail)
  		    break;
  		}
   	      else 
  		{
  		  streamsize __charsread;
! 		  const off_type __size = std::min(__buf_size,
! 						   off_type(__sbout->_M_out_end
! 						   - __sbout->_M_out_cur));
  		  if (__size > 1)
  		    {
  		      _CharT* __buf =
*************** namespace std 
*** 242,248 ****
  		}
   	      if (_Traits::eq_int_type(__sbin->sgetc(), _Traits::eof()))
    		break;
-  	      __in_avail = __sbin->in_avail();
    	    }
  	}
        catch(exception& __fail) 
--- 241,246 ----

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