From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 58159 invoked by alias); 14 Oct 2019 20:12:26 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 58137 invoked by uid 89); 14 Oct 2019 20:12:25 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy=HTo:U*libstdc, friend X-HELO: mail-wm1-f48.google.com Received: from mail-wm1-f48.google.com (HELO mail-wm1-f48.google.com) (209.85.128.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 14 Oct 2019 20:12:24 +0000 Received: by mail-wm1-f48.google.com with SMTP id m18so17975594wmc.1; Mon, 14 Oct 2019 13:12:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=XSYnEAaVipOox5IqC1nw4cSFD1R5AFBh4zx9/dILx1Y=; b=NUHBG6ti6a66ijAa0uW6VRWR4fjaRK/0/O00lpqvLvCDEKGECJCge7xRtzJ/1aw/aO ujA+dhRN0sT/WVu+tvcpFoT3BkDhiAn4mGSmSyIe/QTi8KeZa82ZHCow/j4GuQxbyD5c yobTJ0e7RBcBdmVq1z3eb22MCdj9F1aOl3BWBs4oVu5SCQLr2jvSCbs07Mw+k2oJeH2Q HiUKm5jZfGJRD8H6XBQ78Qw5jBpYFYwsCw9pKs+CWETvCrOzwIRFRTDW16y9wafEMdUO FMPu6IKfDBg7oqu8NPaBTxgUcs3cbQYUW4nVTexkynLZYY9uZrpdi9S8PbRhz59rm3bU urCQ== Return-Path: Received: from ?IPv6:2a01:e0a:1dc:b1c0:f43c:ff52:e76e:590d? ([2a01:e0a:1dc:b1c0:f43c:ff52:e76e:590d]) by smtp.googlemail.com with ESMTPSA id q15sm39570627wrg.65.2019.10.14.13.12.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Oct 2019 13:12:20 -0700 (PDT) To: "libstdc++@gcc.gnu.org" , gcc-patches From: =?UTF-8?Q?Fran=c3=a7ois_Dumont?= Subject: [PATCH] Implement std::advance for istreambuf_iterator using pubseekoff Message-ID: <5531cf67-62b3-a4bc-c611-0fe026b75066@gmail.com> Date: Mon, 14 Oct 2019 20:13:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------09510DA9FD683CB03EBC9EAE" X-SW-Source: 2019-10/txt/msg01011.txt.bz2 This is a multi-part message in MIME format. --------------09510DA9FD683CB03EBC9EAE Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-length: 491 The same way I proposed to review std::copy overload for istreambuf_iterator we can implement std::advance using pubseekoff. It is both a cleaner implementation and avoids yet another friend declaration.     * include/std/streambuf     (advance(istreambuf_iterator<>&, _Distance)): Remove friend declaration.     * include/bits/streambuf_iterator.h (__copy_move_a2): Re-implement using     streambuf pubseekoff. Tested under Linux x86_64. Ok to commit ? François --------------09510DA9FD683CB03EBC9EAE Content-Type: text/x-patch; name="istreambuf_ite_advance.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="istreambuf_ite_advance.patch" Content-length: 2529 diff --git a/libstdc++-v3/include/bits/streambuf_iterator.h b/libstdc++-v3/include/bits/streambuf_iterator.h index 134b3486b9a..afe5c95f021 100644 --- a/libstdc++-v3/include/bits/streambuf_iterator.h +++ b/libstdc++-v3/include/bits/streambuf_iterator.h @@ -434,34 +434,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _M_message(__gnu_debug::__msg_inc_istreambuf) ._M_iterator(__i)); - 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; - const int_type __eof = traits_type::eof(); - - streambuf_type* __sb = __i._M_sbuf; - while (__n > 0) - { - streamsize __size = __sb->egptr() - __sb->gptr(); - if (__size > __n) - { - __sb->__safe_gbump(__n); - break; - } - - __sb->__safe_gbump(__size); - __n -= __size; - if (traits_type::eq_int_type(__sb->underflow(), __eof)) - { - __glibcxx_requires_cond(__n == 0, - _M_message(__gnu_debug::__msg_inc_istreambuf) - ._M_iterator(__i)); - break; - } - } +#ifdef _GLIBCXX_DEBUG + typedef basic_streambuf<_CharT> __streambuf_t; + typedef typename __streambuf_t::pos_type __pos_type; + __pos_type __cur_pos + = __i._M_sbuf->pubseekoff(0, ios_base::cur, ios_base::in); + __pos_type __new_pos = +#endif + __i._M_sbuf->pubseekoff(__n, ios_base::cur, ios_base::in); + __i._M_c = char_traits<_CharT>::eof(); - __i._M_c = __eof; + __glibcxx_requires_cond(__new_pos - __cur_pos == __n, + _M_message(__gnu_debug::__msg_inc_istreambuf) + ._M_iterator(__i)); } // @} group iterators diff --git a/libstdc++-v3/include/std/streambuf b/libstdc++-v3/include/std/streambuf index 3442f19bd78..ef03da39bc2 100644 --- a/libstdc++-v3/include/std/streambuf +++ b/libstdc++-v3/include/std/streambuf @@ -155,11 +155,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION find(istreambuf_iterator<_CharT2>, istreambuf_iterator<_CharT2>, const _CharT2&); - template - friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value, - void>::__type - advance(istreambuf_iterator<_CharT2>&, _Distance); - template friend basic_istream<_CharT2, _Traits2>& operator>>(basic_istream<_CharT2, _Traits2>&, _CharT2*); --------------09510DA9FD683CB03EBC9EAE--