[PATCH 4/4] libstdc++: Rearrange some range adaptors' data members
Jonathan Wakely
jwakely@redhat.com
Mon Sep 28 15:38:38 GMT 2020
On 28/09/20 09:11 -0400, Patrick Palka via Libstdc++ wrote:
>On Mon, 28 Sep 2020, Jonathan Wakely wrote:
>
>> On 28/09/20 00:48 -0400, Patrick Palka via Libstdc++ wrote:
>> > Since the standard range adaptors are specified to derive from the empty
>> > class view_base, making their first data member store the underlying
>> > view is suboptimal, for if the underlying view also derives from
>> > view_base then the two view_base subobjects will be adjacent, thus
>> > preventing the compiler from applying the empty base optimization to
>> > elide away the storage for these two empty bases.
>> >
>> > This patch improves the situation by declaring the _M_base data member
>> > last instead of first in each range adaptor that has more than one data
>> > member, so that the empty base optimization can apply more often.
>> >
>> > Tested on x86_64-pc-linux-gnu with and wihout -m32.
>> >
>> > libstdc++-v3/ChangeLog:
>> >
>> > * include/std/ranges (filter_view::_M_base): Declare this data
>> > member last.
>> > (transform_view::_M_base): Likewise.
>> > (take_view::_M_base): Likewise.
>> > (take_while_view::_M_base): Likewise.
>> > (drop_view::_M_base): Likewise.
>> > (drop_while_view::_M_base): Likewise.
>> > (join_view::_M_base): Likewise.
>> > (split_view::_M_base): Likewise.
>> > * testsuite/std/ranges/adaptors/sizeof.cc: Adjust expected
>> > sizes.
>> > ---
>> > libstdc++-v3/include/std/ranges | 17 ++++++++---------
>> > .../testsuite/std/ranges/adaptors/sizeof.cc | 18 +++++++++---------
>> > 2 files changed, 17 insertions(+), 18 deletions(-)
>> >
>> > diff --git a/libstdc++-v3/include/std/ranges
>> > b/libstdc++-v3/include/std/ranges
>> > index 964a2b616a6..6fd8a85c2bf 100644
>> > --- a/libstdc++-v3/include/std/ranges
>> > +++ b/libstdc++-v3/include/std/ranges
>> > @@ -1250,9 +1250,9 @@ namespace views
>> > { return __y.__equal(__x); }
>> > };
>> >
>> > - _Vp _M_base = _Vp();
>> > [[no_unique_address]] __detail::__box<_Pred> _M_pred;
>> > [[no_unique_address]] __detail::_CachedPosition<_Vp> _M_cached_begin;
>> > + _Vp _M_base = _Vp();
>>
>> The constructor's mem-initializer-list needs to be reordered, to avoid
>> warnings with -Wsystem-headers.
>
>Oops, fixed thusly. I noticed meanwhile that I forgot to move
>reverse_view's _M_base member, so the below patch adds that as well.
Nice to see testsuite/std/ranges/adaptors/sizeof.cc already proving
useful by demonstrating the reduced sizes.
>Tested on x86_64-pc-linux-gnu, and also verified that there are no new
>-Wsystem-headers warnings.
OK, thanks.
More information about the Libstdc++
mailing list