This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch, libstdc++/64584, libstdc++/64585] Clear basic_regex after imbue and make assign exception tolerant


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]