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 3.3] Move over Nathan's __copy_streambufs rewrote


Hi,

a couple of days ago I answered privately an email,
writing that for 3.3 __copy_streambufs was fixed and a few
problems present in 3.2.3 were not present anymore.

This is indeed the case, but, OTOH, it's **so** ugly!

If nobody objects, I would like to move over Nathan's
rewrote. Tested x86-linux. Besides, I'm pretty sure that it
doesn't rely on any other mainline fix.

Paolo.

/////////
2003-05-16  Nathan Myers  <ncm@cantrip.org>

	* include/bits/streambuf.tcc (__copy_streambufs): Rewrote.
diff -prN libstdc++-v3-orig/include/bits/streambuf.tcc libstdc++-v3/include/bits/streambuf.tcc
*** libstdc++-v3-orig/include/bits/streambuf.tcc	Sun Mar  9 12:25:11 2003
--- libstdc++-v3/include/bits/streambuf.tcc	Fri May 16 20:43:16 2003
*************** namespace std 
*** 198,270 ****
  		      basic_streambuf<_CharT, _Traits>* __sbin,
  		      basic_streambuf<_CharT, _Traits>* __sbout) 
    {
!       typedef typename _Traits::int_type	int_type;
! 
!       streamsize __ret = 0;
!       streamsize __bufsize = __sbin->in_avail();
!       streamsize __xtrct;
!       const typename _Traits::off_type __size_opt =
! 	__sbin->_M_buf_size_opt > 0 ? __sbin->_M_buf_size_opt : 1;
! 
!       try 
! 	{
! 	  while (__bufsize != -1)
!   	    {
!  	      if (__bufsize != 0 && __sbin->gptr() != NULL
! 		  && __sbin->gptr() + __bufsize <= __sbin->egptr()) 
! 		{
! 		  __xtrct = __sbout->sputn(__sbin->gptr(), __bufsize);
! 		  __ret += __xtrct;
! 		  __sbin->_M_in_cur_move(__xtrct);
! 		  if (__xtrct != __bufsize)
! 		    break;
! 		}
!  	      else 
! 		{
! 		  streamsize __charsread;
! 		  const streamsize __size =
! 		    min(__size_opt, __sbout->_M_out_buf_size());
! 		  if (__size > 1)
! 		    {
! 		      _CharT* __buf =
! 			static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
! 							      * __size));
! 		      // Since the next sputn cannot fail sgetn can be
! 		      // safely used.
! 		      __charsread = __sbin->sgetn(__buf, __size);
! 		      __xtrct = __sbout->sputn(__buf, __charsread);
! 		    }
! 		  else
! 		    {
! 		      __xtrct = __charsread = 0;
! 		      int_type __c = __sbin->sgetc();
! 		      while (!_Traits::eq_int_type(__c, _Traits::eof()))
! 			{
! 			  ++__charsread;
! 			  if (_Traits::eq_int_type(__sbout->sputc(_Traits::to_char_type(__c)),
! 						   _Traits::eof()))
! 			    break;
! 			  ++__xtrct;
! 			  __c = __sbin->snextc();
! 			}
! 		    }		      
! 		  __ret += __xtrct;
! 		  if (__xtrct != __charsread)
! 		    break;
! 		}
!  	      if (_Traits::eq_int_type(__sbin->sgetc(), _Traits::eof()))
!   		break;
!  	      __bufsize = __sbin->in_avail();
!   	    }
! 	}
!       catch(exception& __fail) 
! 	{
! 	  __ios.setstate(ios_base::failbit);
! 	  if ((__ios.exceptions() & ios_base::failbit) != 0)
! 	    __throw_exception_again;
! 	}
!       return __ret;
!     }
  
    // Inhibit implicit instantiations for required instantiations,
    // which are defined via explicit instantiations elsewhere.  
--- 198,238 ----
  		      basic_streambuf<_CharT, _Traits>* __sbin,
  		      basic_streambuf<_CharT, _Traits>* __sbout) 
    {
!     streamsize __ret = 0;
!     try 
!       {
! 	typename _Traits::int_type __c = __sbin->sgetc();
! 	while (!_Traits::eq_int_type(__c, _Traits::eof()))
! 	  {
! 	    const size_t __n = __sbin->_M_in_end - __sbin->_M_in_cur;
! 	    if (__n > 1)
! 	      {
! 		const size_t __wrote = __sbout->sputn(__sbin->_M_in_cur,
! 						      __n);
! 		__sbin->_M_in_cur_move(__wrote);
! 		__ret += __wrote;
! 		if (__wrote < __n)
! 		  break;
! 		__c = __sbin->underflow();
! 	      }
! 	    else 
! 	      {
! 		__c = __sbout->sputc(_Traits::to_char_type(__c));
! 		if (_Traits::eq_int_type(__c, _Traits::eof()))
! 		  break;
! 		++__ret;
! 		__c = __sbin->snextc();
! 	      }
! 	  }
!       }
!     catch(exception& __fail) 
!       {
! 	__ios.setstate(ios_base::failbit);
! 	if ((__ios.exceptions() & ios_base::failbit) != 0)
! 	  __throw_exception_again;
!       }
!     return __ret;
!   }
  
    // Inhibit implicit instantiations for required instantiations,
    // which are defined via explicit instantiations elsewhere.  

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