]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Micro-optimization for std::addressof
authorJonathan Wakely <jwakely@redhat.com>
Fri, 25 Apr 2025 14:49:22 +0000 (15:49 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 25 Apr 2025 19:36:55 +0000 (20:36 +0100)
Currently std::addressof calls std::__addressof which uses
__builtin_addressof. This leads to me prefering std::__addressof in some
code, to avoid the extra hop. But it's not as though the implementation
of std::__addressof is complicated and reusing it avoids any code
duplication.

So let's just make std::addressof use the built-in directly, and then we
only need to use std::__addressof in C++98 code. (Transitioning existing
uses of std::__addressof to std::addressof isn't included in this
change.)

The front end does fold std::addressof with -ffold-simple-inlines but
this change still seems worthwhile.

libstdc++-v3/ChangeLog:

* include/bits/move.h (addressof): Use __builtin_addressof
directly.

libstdc++-v3/include/bits/move.h

index e91b003e695525d4eac8b0c5e8c4ef3d4af48907..085ca074fc88d574dd0ec237bc2baa4b3b16d7d6 100644 (file)
@@ -174,7 +174,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     [[__nodiscard__,__gnu__::__always_inline__]]
     inline _GLIBCXX17_CONSTEXPR _Tp*
     addressof(_Tp& __r) noexcept
-    { return std::__addressof(__r); }
+    { return __builtin_addressof(__r); }
 
   // _GLIBCXX_RESOLVE_LIB_DEFECTS
   // 2598. addressof works on temporaries