From patchwork Sat Nov 19 17:44:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 60884 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 94F203853D59 for ; Sat, 19 Nov 2022 17:45:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 94F203853D59 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668879927; bh=VAkERuRCU+EyqEch4bsxbn/PM4ubnZ+kNax1wAb3m+Q=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=o3xHVTJBdIACYcjW7tkDpyy1a5o0ipl04OvS8nGe7z/caf3ItdqvrP5DyXO1L+rTl jVHW9289lP+vKGXgSyo6rAYZqsHY0aOwzna16J4dCKhtvLW9/OxQLnNKW659IOwIla BY3oXn4IY3oRjB85Mf6HohkqAyxm7P6vWyEMDVvk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 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) 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 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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; }