]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Remove unnecessary tag dispatching in std::vector
authorJonathan Wakely <jwakely@redhat.com>
Tue, 29 Nov 2022 15:19:33 +0000 (15:19 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 29 Nov 2022 16:01:08 +0000 (16:01 +0000)
There's no need to call a _M_xxx_dispatch function with a
statically-known __false_type tag, we can just directly call the
function that should be dispatched to. This will compile a tiny bit
faster and save a function call with optimization or inlining turned
off.

Also add the always_inline attribute to the __iterator_category helper
used for dispatching on the iterator category.

libstdc++-v3/ChangeLog:

* include/bits/stl_iterator_base_types.h (__iterator_category):
Add always_inline attribute.
* include/bits/stl_vector.h (assign(Iter, Iter)): Call
_M_assign_aux directly, instead of _M_assign_dispatch.
(insert(const_iterator, Iter, Iter)): Call _M_range_insert
directly instead of _M_insert_dispatch.

libstdc++-v3/include/bits/stl_iterator_base_types.h
libstdc++-v3/include/bits/stl_vector.h

index 9eecd1dd855c5728f1b7bcc0e6f5af681ab1a059..5d90c0d8ea73dba7a2ab0f594770804b3b918fcb 100644 (file)
@@ -233,6 +233,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    *  sugar for internal library use only.
   */
   template<typename _Iter>
+    __attribute__((__always_inline__))
     inline _GLIBCXX_CONSTEXPR
     typename iterator_traits<_Iter>::iterator_category
     __iterator_category(const _Iter&)
index b4ff3989a5dd5555949a212b236ed54be7e670fb..e87fab0e51cf15407870148eb6ecf9d4c6b25049 100644 (file)
@@ -821,7 +821,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
        _GLIBCXX20_CONSTEXPR
        void
        assign(_InputIterator __first, _InputIterator __last)
-       { _M_assign_dispatch(__first, __last, __false_type()); }
+       { _M_assign_aux(__first, __last, std::__iterator_category(__first)); }
 #else
       template<typename _InputIterator>
        void
@@ -1478,8 +1478,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
               _InputIterator __last)
        {
          difference_type __offset = __position - cbegin();
-         _M_insert_dispatch(begin() + __offset,
-                            __first, __last, __false_type());
+         _M_range_insert(begin() + __offset, __first, __last,
+                         std::__iterator_category(__first));
          return begin() + __offset;
        }
 #else