* [PATCH] Review std::copy istreambuf_iterator specialization
@ 2019-10-09 4:42 François Dumont
0 siblings, 0 replies; only message in thread
From: François Dumont @ 2019-10-09 4:42 UTC (permalink / raw)
To: libstdc++, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 492 bytes --]
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
[-- Attachment #2: istreambuf_copy.patch --]
[-- Type: text/x-patch, Size: 2168 bytes --]
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2019-10-09 4:42 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-09 4:42 [PATCH] Review std::copy istreambuf_iterator specialization François Dumont
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).