From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id B8A143853D4A for ; Sat, 19 Nov 2022 17:44:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B8A143853D4A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668879898; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=VAkERuRCU+EyqEch4bsxbn/PM4ubnZ+kNax1wAb3m+Q=; b=EqkmlXbmyizAQu45qYdXEFj2ehiMho8bXJfM8gzuA+pDCrCdmta0v2a8N5KzYSieadNuru e9u+iGOHBGYI6siOnTam92fN75EqgPo1U1oZxlfIUYa2qz2yeF+UcO9KwTJPEiyBtsp8Id ZxJjJkruYqpw+Bg7/TArrIHasP/sJig= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-227-ruXwu4fhMtmHUk3YztUnHw-1; Sat, 19 Nov 2022 12:44:56 -0500 X-MC-Unique: ruXwu4fhMtmHUk3YztUnHw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8F0E1802314; Sat, 19 Nov 2022 17:44:56 +0000 (UTC) Received: from localhost (unknown [10.33.36.199]) by smtp.corp.redhat.com (Postfix) with ESMTP id 555D5C15BAB; Sat, 19 Nov 2022 17:44:56 +0000 (UTC) From: Jonathan Wakely 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 Message-Id: <20221119174453.1688270-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 - [[__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 - [[__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 - [[__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 - [[__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 - [[__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 - [[__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 - [[__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 - [[__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 - [[__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 - [[__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 - [[__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 - [[__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 - [[__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 - [[__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 - [[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 - [[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 - [[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 - [[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 - [[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 - [[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 - [[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 - [[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 - [[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 - [[nodiscard]] + [[nodiscard, __gnu__::__always_inline__]] constexpr auto ssize(const _Container& __cont) noexcept(noexcept(__cont.size())) @@ -357,7 +360,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - [[nodiscard]] + [[nodiscard, __gnu__::__always_inline__]] constexpr ptrdiff_t ssize(const _Tp (&)[_Num]) noexcept { return _Num; } -- 2.38.1