From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 58909 invoked by alias); 1 May 2015 20:05:52 -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 58889 invoked by uid 89); 1 May 2015 20:05:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 01 May 2015 20:05:50 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t41K5m5K020248 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 1 May 2015 16:05:48 -0400 Received: from localhost (ovpn-116-62.ams2.redhat.com [10.36.116.62]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t41K5l1J025770; Fri, 1 May 2015 16:05:48 -0400 Date: Fri, 01 May 2015 20:05:00 -0000 From: Jonathan Wakely To: Daniel =?iso-8859-1?Q?Kr=FCgler?= Cc: libstdc++ , gcc-patches List Subject: Re: [patch] Implement ISO/IEC TS 18822 C++ File system TS Message-ID: <20150501200547.GL3618@redhat.com> References: <20150430173236.GT3618@redhat.com> <20150501182223.GI3618@redhat.com> <20150501193816.GJ3618@redhat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="6B5oiwbC31sfIr4n" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20150501193816.GJ3618@redhat.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-SW-Source: 2015-05/txt/msg00099.txt.bz2 --6B5oiwbC31sfIr4n Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit Content-length: 1282 On 01/05/15 20:38 +0100, Jonathan Wakely wrote: >On 01/05/15 21:28 +0200, Daniel Krügler wrote: >>But if I read your implementation of path::compare(const path& p) >>correctly it *also* may allocate memory by copying _M_pathname into a >>_Cmpt object. > >Yes, I agree that there's a bug here that could cause it to >std::terminate. > >>I was wondering whether for this comparison there exists >>real need to *copy* _M_pathname (potentially exceeding the memory >>limits). Wouldn't it be possible to define a _CmptRef type that for >>the purpose of implementing compare(const path& p) just refers to >>references of the _M_pathname and therefore doesn't need to allocate >>any dynamic storage? (I should have spoken of a new type _CmptRef and >>not of your existing _Cmpt). > > >Ah, I see what you mean (I thought you were suggesting some >improvements to _Cmpt itself ... which might be possible so I'm glad >you made me think about it :-) > >I think I wrote compare() like that because it was easier, and when I >first implemented this we had COW strings so it wouldn't throw when >copying. That isn't true now, so I need to change it. And here's the fix for this noexcept issue, it was very simple in the end, thanks for the idea. Tested powerpc64le-linux, committed to trunk. --6B5oiwbC31sfIr4n Content-Type: text/x-patch; charset=us-ascii Content-Disposition: attachment; filename="patch.txt" Content-length: 1216 commit 9c2f4abea2096bcc5e3568facf12fb3550358c6b Author: Jonathan Wakely Date: Fri May 1 20:57:21 2015 +0100 * src/filesystem/path.cc (path::compare): Do not copy strings. diff --git a/libstdc++-v3/src/filesystem/path.cc b/libstdc++-v3/src/filesystem/path.cc index cc5780f..7924732 100644 --- a/libstdc++-v3/src/filesystem/path.cc +++ b/libstdc++-v3/src/filesystem/path.cc @@ -107,17 +107,23 @@ namespace int path::compare(const path& p) const noexcept { + struct CmptRef + { + const path* ptr; + const string_type& native() const noexcept { return ptr->native(); } + }; + if (_M_type == _Type::_Multi && p._M_type == _Type::_Multi) return do_compare(_M_cmpts.begin(), _M_cmpts.end(), p._M_cmpts.begin(), p._M_cmpts.end()); else if (_M_type == _Type::_Multi) { - _Cmpt c[1] = { { p._M_pathname, p._M_type, 0 } }; + CmptRef c[1] = { { &p } }; return do_compare(_M_cmpts.begin(), _M_cmpts.end(), c, c+1); } else if (p._M_type == _Type::_Multi) { - _Cmpt c[1] = { { _M_pathname, _M_type, 0 } }; + CmptRef c[1] = { { this } }; return do_compare(c, c+1, p._M_cmpts.begin(), p._M_cmpts.end()); } else --6B5oiwbC31sfIr4n--