public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* vector<bool> _M_start and 0 offset
@ 2018-09-15 14:12 Marc Glisse
  2018-09-17 16:29 ` Jonathan Wakely
  0 siblings, 1 reply; 14+ messages in thread
From: Marc Glisse @ 2018-09-15 14:12 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: TEXT/PLAIN, Size: 871 bytes --]

Hello,

as explained in the PR, the implementation of vector<bool> is weirdly 
wasteful. Preserving the ABI prevents from changing much for now, but this 
small tweak can help the compiler remove quite a bit of dead code.

I think most other direct uses of _M_start are in constructors where the 
offset has just been initialized to 0, so the compiler should already know 
enough there, but I may have missed a few relevant places where the same 
idea could be used.

I used C++11 syntax because I find it nicer, and the compiler accepts it 
in C++98 mode with just a warning, suppressed in a standard header.

Bootstrap+regtest on powerpc64le-unknown-linux-gnu.

2018-09-15  Marc Glisse  <marc.glisse@inria.fr>

         PR libstdc++/87258
 	* include/bits/stl_bvector.h (vector::begin(), vector::cbegin()):
 	Rebuild _M_start with an explicit 0 offset.

-- 
Marc Glisse

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: TEXT/x-diff; name=vbool.patch, Size: 1692 bytes --]

Index: include/bits/stl_bvector.h
===================================================================
--- include/bits/stl_bvector.h	(revision 264178)
+++ include/bits/stl_bvector.h	(working copy)
@@ -802,25 +802,25 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 #endif
 
 #if __cplusplus >= 201103L
       void
       assign(initializer_list<bool> __l)
       { _M_assign_aux(__l.begin(), __l.end(), random_access_iterator_tag()); }
 #endif
 
       iterator
       begin() _GLIBCXX_NOEXCEPT
-      { return this->_M_impl._M_start; }
+      { return { this->_M_impl._M_start._M_p, 0 }; }
 
       const_iterator
       begin() const _GLIBCXX_NOEXCEPT
-      { return this->_M_impl._M_start; }
+      { return { this->_M_impl._M_start._M_p, 0 }; }
 
       iterator
       end() _GLIBCXX_NOEXCEPT
       { return this->_M_impl._M_finish; }
 
       const_iterator
       end() const _GLIBCXX_NOEXCEPT
       { return this->_M_impl._M_finish; }
 
       reverse_iterator
@@ -835,21 +835,21 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
       rend() _GLIBCXX_NOEXCEPT
       { return reverse_iterator(begin()); }
 
       const_reverse_iterator
       rend() const _GLIBCXX_NOEXCEPT
       { return const_reverse_iterator(begin()); }
 
 #if __cplusplus >= 201103L
       const_iterator
       cbegin() const noexcept
-      { return this->_M_impl._M_start; }
+      { return { this->_M_impl._M_start._M_p, 0 }; }
 
       const_iterator
       cend() const noexcept
       { return this->_M_impl._M_finish; }
 
       const_reverse_iterator
       crbegin() const noexcept
       { return const_reverse_iterator(end()); }
 
       const_reverse_iterator

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2018-10-01 12:13 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-15 14:12 vector<bool> _M_start and 0 offset Marc Glisse
2018-09-17 16:29 ` Jonathan Wakely
2018-09-17 18:20   ` Marc Glisse
2018-09-17 18:55     ` Jonathan Wakely
2018-09-17 19:10       ` Ville Voutilainen
2018-09-17 19:12         ` Jonathan Wakely
2018-09-17 19:18           ` Jonathan Wakely
2018-09-17 19:22           ` Marc Glisse
2018-09-17 19:28             ` Marc Glisse
2018-09-17 19:50               ` Jonathan Wakely
2018-09-17 20:05                 ` Marc Glisse
2018-09-29 11:06                 ` Marc Glisse
2018-10-01 12:45                   ` Jonathan Wakely
2018-09-17 19:36             ` Jonathan Wakely

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).