From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed] libstdc++: Add always_inline to trivial range access functions
Date: Sat, 19 Nov 2022 17:44:53 +0000 [thread overview]
Message-ID: <20221119174453.1688270-1-jwakely@redhat.com> (raw)
Tested x86_64-linux. Pushed to trunk.
-- >8 --
This makes all the [iterator.range] functions always-inline, except the
ones that construct a std::reverse_iterator, as they do a little more
work. They could probably be made always_inline too though, and maybe
the std::reverse_iterator constructor too.
This means that even for -O0 these functions have no runtime overhead
compared with calling a member of the container, or performing pointer
arithmetic for arrays.
libstdc++-v3/ChangeLog:
* include/bits/range_access.h: Add always_inline attribute to
trivial functions.
---
libstdc++-v3/include/bits/range_access.h | 53 +++++++++++++-----------
1 file changed, 28 insertions(+), 25 deletions(-)
diff --git a/libstdc++-v3/include/bits/range_access.h b/libstdc++-v3/include/bits/range_access.h
index 78fdfe66035..241f5417eec 100644
--- a/libstdc++-v3/include/bits/range_access.h
+++ b/libstdc++-v3/include/bits/range_access.h
@@ -47,7 +47,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __cont Container.
*/
template<typename _Container>
- [[__nodiscard__]]
+ [[__nodiscard__, __gnu__::__always_inline__]]
inline _GLIBCXX17_CONSTEXPR auto
begin(_Container& __cont) -> decltype(__cont.begin())
{ return __cont.begin(); }
@@ -58,7 +58,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __cont Container.
*/
template<typename _Container>
- [[__nodiscard__]]
+ [[__nodiscard__, __gnu__::__always_inline__]]
inline _GLIBCXX17_CONSTEXPR auto
begin(const _Container& __cont) -> decltype(__cont.begin())
{ return __cont.begin(); }
@@ -69,7 +69,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __cont Container.
*/
template<typename _Container>
- [[__nodiscard__]]
+ [[__nodiscard__, __gnu__::__always_inline__]]
inline _GLIBCXX17_CONSTEXPR auto
end(_Container& __cont) -> decltype(__cont.end())
{ return __cont.end(); }
@@ -80,7 +80,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __cont Container.
*/
template<typename _Container>
- [[__nodiscard__]]
+ [[__nodiscard__, __gnu__::__always_inline__]]
inline _GLIBCXX17_CONSTEXPR auto
end(const _Container& __cont) -> decltype(__cont.end())
{ return __cont.end(); }
@@ -90,7 +90,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __arr Array.
*/
template<typename _Tp, size_t _Nm>
- [[__nodiscard__]]
+ [[__nodiscard__, __gnu__::__always_inline__]]
inline _GLIBCXX14_CONSTEXPR _Tp*
begin(_Tp (&__arr)[_Nm]) noexcept
{ return __arr; }
@@ -101,7 +101,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __arr Array.
*/
template<typename _Tp, size_t _Nm>
- [[__nodiscard__]]
+ [[__nodiscard__, __gnu__::__always_inline__]]
inline _GLIBCXX14_CONSTEXPR _Tp*
end(_Tp (&__arr)[_Nm]) noexcept
{ return __arr + _Nm; }
@@ -121,7 +121,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __cont Container.
*/
template<typename _Container>
- [[__nodiscard__]]
+ [[__nodiscard__, __gnu__::__always_inline__]]
constexpr auto
cbegin(const _Container& __cont) noexcept(noexcept(std::begin(__cont)))
-> decltype(std::begin(__cont))
@@ -133,7 +133,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __cont Container.
*/
template<typename _Container>
- [[__nodiscard__]]
+ [[__nodiscard__, __gnu__::__always_inline__]]
constexpr auto
cend(const _Container& __cont) noexcept(noexcept(std::end(__cont)))
-> decltype(std::end(__cont))
@@ -145,7 +145,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __cont Container.
*/
template<typename _Container>
- [[__nodiscard__]]
+ [[__nodiscard__, __gnu__::__always_inline__]]
inline _GLIBCXX17_CONSTEXPR auto
rbegin(_Container& __cont) -> decltype(__cont.rbegin())
{ return __cont.rbegin(); }
@@ -156,7 +156,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __cont Container.
*/
template<typename _Container>
- [[__nodiscard__]]
+ [[__nodiscard__, __gnu__::__always_inline__]]
inline _GLIBCXX17_CONSTEXPR auto
rbegin(const _Container& __cont) -> decltype(__cont.rbegin())
{ return __cont.rbegin(); }
@@ -167,7 +167,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __cont Container.
*/
template<typename _Container>
- [[__nodiscard__]]
+ [[__nodiscard__, __gnu__::__always_inline__]]
inline _GLIBCXX17_CONSTEXPR auto
rend(_Container& __cont) -> decltype(__cont.rend())
{ return __cont.rend(); }
@@ -178,7 +178,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __cont Container.
*/
template<typename _Container>
- [[__nodiscard__]]
+ [[__nodiscard__, __gnu__::__always_inline__]]
inline _GLIBCXX17_CONSTEXPR auto
rend(const _Container& __cont) -> decltype(__cont.rend())
{ return __cont.rend(); }
@@ -233,7 +233,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __cont Container.
*/
template<typename _Container>
- [[__nodiscard__]]
+ [[__nodiscard__, __gnu__::__always_inline__]]
inline _GLIBCXX17_CONSTEXPR auto
crbegin(const _Container& __cont) -> decltype(std::rbegin(__cont))
{ return std::rbegin(__cont); }
@@ -244,7 +244,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __cont Container.
*/
template<typename _Container>
- [[__nodiscard__]]
+ [[__nodiscard__, __gnu__::__always_inline__]]
inline _GLIBCXX17_CONSTEXPR auto
crend(const _Container& __cont) -> decltype(std::rend(__cont))
{ return std::rend(__cont); }
@@ -259,7 +259,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __cont Container.
*/
template <typename _Container>
- [[nodiscard]]
+ [[nodiscard, __gnu__::__always_inline__]]
constexpr auto
size(const _Container& __cont) noexcept(noexcept(__cont.size()))
-> decltype(__cont.size())
@@ -269,7 +269,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @brief Return the size of an array.
*/
template <typename _Tp, size_t _Nm>
- [[nodiscard]]
+ [[nodiscard, __gnu__::__always_inline__]]
constexpr size_t
size(const _Tp (&)[_Nm]) noexcept
{ return _Nm; }
@@ -279,7 +279,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __cont Container.
*/
template <typename _Container>
- [[nodiscard]] constexpr auto
+ [[nodiscard, __gnu__::__always_inline__]]
+ constexpr auto
empty(const _Container& __cont) noexcept(noexcept(__cont.empty()))
-> decltype(__cont.empty())
{ return __cont.empty(); }
@@ -288,7 +289,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @brief Return whether an array is empty (always false).
*/
template <typename _Tp, size_t _Nm>
- [[nodiscard]] constexpr bool
+ [[nodiscard, __gnu__::__always_inline__]]
+ constexpr bool
empty(const _Tp (&)[_Nm]) noexcept
{ return false; }
@@ -297,7 +299,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __il Initializer list.
*/
template <typename _Tp>
- [[nodiscard]] constexpr bool
+ [[nodiscard, __gnu__::__always_inline__]]
+ constexpr bool
empty(initializer_list<_Tp> __il) noexcept
{ return __il.size() == 0;}
@@ -306,7 +309,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __cont Container.
*/
template <typename _Container>
- [[nodiscard]]
+ [[nodiscard, __gnu__::__always_inline__]]
constexpr auto
data(_Container& __cont) noexcept(noexcept(__cont.data()))
-> decltype(__cont.data())
@@ -317,7 +320,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __cont Container.
*/
template <typename _Container>
- [[nodiscard]]
+ [[nodiscard, __gnu__::__always_inline__]]
constexpr auto
data(const _Container& __cont) noexcept(noexcept(__cont.data()))
-> decltype(__cont.data())
@@ -328,7 +331,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __array Array.
*/
template <typename _Tp, size_t _Nm>
- [[nodiscard]]
+ [[nodiscard, __gnu__::__always_inline__]]
constexpr _Tp*
data(_Tp (&__array)[_Nm]) noexcept
{ return __array; }
@@ -338,7 +341,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __il Initializer list.
*/
template <typename _Tp>
- [[nodiscard]]
+ [[nodiscard, __gnu__::__always_inline__]]
constexpr const _Tp*
data(initializer_list<_Tp> __il) noexcept
{ return __il.begin(); }
@@ -346,7 +349,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#if __cplusplus > 201703L
#define __cpp_lib_ssize 201902L
template<typename _Container>
- [[nodiscard]]
+ [[nodiscard, __gnu__::__always_inline__]]
constexpr auto
ssize(const _Container& __cont)
noexcept(noexcept(__cont.size()))
@@ -357,7 +360,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
template<typename _Tp, ptrdiff_t _Num>
- [[nodiscard]]
+ [[nodiscard, __gnu__::__always_inline__]]
constexpr ptrdiff_t
ssize(const _Tp (&)[_Num]) noexcept
{ return _Num; }
--
2.38.1
reply other threads:[~2022-11-19 17:45 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20221119174453.1688270-1-jwakely@redhat.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
/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).