This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [Patch, libstdc++/64584, libstdc++/64585] Clear basic_regex after imbue and make assign exception tolerant
- From: Jonathan Wakely <jwakely at redhat dot com>
- To: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Fri, 16 Jan 2015 13:39:29 +0000
- Subject: Re: [Patch, libstdc++/64584, libstdc++/64585] Clear basic_regex after imbue and make assign exception tolerant
- Authentication-results: sourceware.org; auth=none
- References: <CAG4ZjNmMbv4c-bix8VZV8CrudrZZOgMas3cKPhLwoiTnPOMUCA at mail dot gmail dot com> <20150116121217 dot GA3360 at redhat dot com> <alpine dot DEB dot 2 dot 11 dot 1501161419450 dot 1655 at laptop-mg dot saclay dot inria dot fr>
On 16/01/15 14:34 +0100, Marc Glisse wrote:
On Fri, 16 Jan 2015, Jonathan Wakely wrote:
Am I missing something here, why are you moving the iterators?
Iterators are cheap to copy, so moving them is not necessary.
(I am not talking about this patch in particular)
Iterators are supposed to be relatively cheap to copy. In practice,
that copy doesn't always come for free. When you implemented
filesystem iterators, IIRC you had at least a shared_ptr in your
iterators, so copying involved some atomic operations and those have a
cost (first a direct cost on the system, but also an optimization cost
because we can't simplify 5 consecutive copies to only one). I have
seen iterators that were even more expensive (and inconvenient to make
cheaper). If we can internally reduce the number of copies (move
instead, pass by reference, etc), that seems good to me. I wanted to
make a pass on predefined_ops.h but didn't find the time.
In general I agree, but for regex the iterators are _usually_ going to
be pointers, because we try to unwrap string iterators to get raw
pointers, so we only use the Foo<const char*> specializations and not
Foo<std::string::iterator> as well.
If std::move on a pointer definitely doesn't pessimize, then I suppose
it's no worse and the move is OK.