Review std::copy istreambuf_iterator specialization
diff mbox series

Message ID f9d4b6ca-cc97-5ead-3fe8-bfa99a6cc0b8@gmail.com
State New
Headers show
Series
  • Review std::copy istreambuf_iterator specialization
Related show

Commit Message

François Dumont Oct. 9, 2019, 4:42 a.m. UTC
Hi

     Following what has been done for std::copy_n I think we could 
simplify the __copy_move_a2 overload to also use sgetn. Code is simpler 
and we avoid a friend declaration.

     Tested under Linux x86_64.


     * include/std/streambuf (__copy_move_a2): Remove friend declaration.
     * include/bits/streambuf_iterator.h (__copy_move_a2): Re-implement 
using
     streambuf in_avail and sgetn.

     Ok to commit ?

François

Patch
diff mbox series

diff --git a/libstdc++-v3/include/bits/streambuf_iterator.h b/libstdc++-v3/include/bits/streambuf_iterator.h
index e3e8736e768..134b3486b9a 100644
--- a/libstdc++-v3/include/bits/streambuf_iterator.h
+++ b/libstdc++-v3/include/bits/streambuf_iterator.h
@@ -345,31 +345,19 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
 		   istreambuf_iterator<_CharT> __last, _CharT* __result)
     {
       typedef istreambuf_iterator<_CharT>		   __is_iterator_type;
-      typedef typename __is_iterator_type::traits_type	   traits_type;
       typedef typename __is_iterator_type::streambuf_type  streambuf_type;
-      typedef typename traits_type::int_type		   int_type;
 
       if (__first._M_sbuf && !__last._M_sbuf)
 	{
 	  streambuf_type* __sb = __first._M_sbuf;
-	  int_type __c = __sb->sgetc();
-	  while (!traits_type::eq_int_type(__c, traits_type::eof()))
+	  std::streamsize __avail = __sb->in_avail();
+	  while (__avail > 0)
 	    {
-	      const streamsize __n = __sb->egptr() - __sb->gptr();
-	      if (__n > 1)
-		{
-		  traits_type::copy(__result, __sb->gptr(), __n);
-		  __sb->__safe_gbump(__n);
-		  __result += __n;
-		  __c = __sb->underflow();
-		}
-	      else
-		{
-		  *__result++ = traits_type::to_char_type(__c);
-		  __c = __sb->snextc();
-		}
+	      __result += __sb->sgetn(__result, __avail);
+	      __avail = __sb->in_avail();
 	    }
 	}
+
       return __result;
     }
 
diff --git a/libstdc++-v3/include/std/streambuf b/libstdc++-v3/include/std/streambuf
index d9ca981d704..3442f19bd78 100644
--- a/libstdc++-v3/include/std/streambuf
+++ b/libstdc++-v3/include/std/streambuf
@@ -149,12 +149,6 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
       friend streamsize
       __copy_streambufs_eof<>(basic_streambuf*, basic_streambuf*, bool&);
 
-      template<bool _IsMove, typename _CharT2>
-        friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
-					       _CharT2*>::__type
-        __copy_move_a2(istreambuf_iterator<_CharT2>,
-		       istreambuf_iterator<_CharT2>, _CharT2*);
-
       template<typename _CharT2>
         friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
 				  istreambuf_iterator<_CharT2> >::__type