From: Jonathan Wakely <jwakely@redhat.com>
To: Marc Glisse <marc.glisse@inria.fr>
Cc: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: Re: [libstdc++/61347] std::distance(list.first(),list.end()) in O(1)
Date: Mon, 13 Apr 2015 15:11:00 -0000 [thread overview]
Message-ID: <20150413151057.GK9755@redhat.com> (raw)
In-Reply-To: <alpine.DEB.2.11.1504131549210.13447@stedding.saclay.inria.fr>
On 13/04/15 16:14 +0200, Marc Glisse wrote:
>On Mon, 13 Apr 2015, Jonathan Wakely wrote:
>
>>On 13/04/15 13:42 +0200, Marc Glisse wrote:
>>>this patch makes std::distance(list.first(),list.end()) a constant
>>>time operation when optimizing, with no penalty for other calls.
>>>We could do the test always (no __builtin_constant_p) but then it
>>>will add a small runtime penalty for other calls, someone else can
>>>take responsibility for that.
>>
>>I like the way you've done it. No penalty for other calls is great
>>and IMHO it's OK that the optimisation only happens when optimising.
>>
>>(Does it work even at -Og?)
>
>No, the testcase currently passes with -O1 but not -Og.
OK, we can live with that.
>>Sadly, that node is going to look even stranger when I finish adding
>>support for C++11 allocators, as the type of node becomes dependent on
>>the allocator's pointer, which makes _List_node<size_t> much more
>>complicated :-(
>
>But then I assume _List_node_base is the part really getting more
>complicated, so without looking too closely it seems almost
>orthogonal.
In order to avoid making any changes to std::list<T, std::allocator<T>>
I'm adding an entire parallel hierarchy of a new node base type
(parameterized on the allocator's void_pointer type), a new node type
and new iterators (parameterized on the pointer type), which will only
be used when !is_pointer<Alloc::pointer>. So it will just mean adding
two new overloads for the two new iterator types.
Not a big deal, as long as I remember to do it :-)
>>This should still be a qualified call to std::__distance, otherwise the
>>compiler might end up instantiating things to figure out if there are
>>any associated namespaces, e.g. for vector<unique_ptr<T>>::iterator we
>>don't want to know T's base classes and rheir associated namespaces.
>
>Then the approach will not work. C++ overload resolution will not
>consider the later __distance declarations in stl_list.h if the call
>is qualified (I didn't change it gratuitously).
Ahhh, yes, of course.
>A forward declaration
>of list iterators and those __distance overloads in
>bits/stl_iterator_base_funcs.h is not very appealing but may work (or
>it may cause issues, I don't know). Otherwise, I guess we are back to
>creating a new file bits/list_iterator.h, which <list> includes if
><iterator> has already been included and vice versa, and which
>provides overloads for distance directly.
I don't have a preference, but I think the forward declarations should
work without problems. <list> includes bits/stl_iterator_base_funcs.h
so if the forward declarations didn't match the definitions for some
reason we'd know right away.
next prev parent reply other threads:[~2015-04-13 15:11 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-13 11:42 Marc Glisse
2015-04-13 13:40 ` Jonathan Wakely
2015-04-13 14:15 ` Marc Glisse
2015-04-13 15:11 ` Jonathan Wakely [this message]
2015-04-14 8:24 ` Marc Glisse
2015-04-14 9:32 ` Jonathan Wakely
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150413151057.GK9755@redhat.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
--cc=marc.glisse@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).