libstdc++: Remove execution branch in deque iterator operator-
authorFrançois Dumont <fdumont@gcc.gnu.org>
Thu, 4 Feb 2021 05:45:18 +0000 (06:45 +0100)
committerFrançois Dumont <fdumont@gcc.gnu.org>
Tue, 9 Feb 2021 20:56:27 +0000 (21:56 +0100)
libstdc++-v3/ChangeLog:

* include/bits/stl_deque.h
(std::operator-(deque::iterator, deque::iterator)): Replace if/then with
a null pointer test.

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

index 04b70b776218320765d2d2a193432416d723b815..8bba7a3740f18086f989f5b420bfb59df39db70f 100644 (file)
@@ -352,12 +352,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
       friend difference_type
       operator-(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPT
       {
-       if (__builtin_expect(__x._M_node || __y._M_node, true))
-         return difference_type(_S_buffer_size())
-           * (__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first)
-           + (__y._M_last - __y._M_cur);
-
-       return 0;
+       return difference_type(_S_buffer_size())
+         * (__x._M_node - __y._M_node - int(__x._M_node != 0))
+         + (__x._M_cur - __x._M_first)
+         + (__y._M_last - __y._M_cur);
       }
 
       // _GLIBCXX_RESOLVE_LIB_DEFECTS
@@ -369,12 +367,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
        operator-(const _Self& __x,
                  const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT
        {
-         if (__builtin_expect(__x._M_node || __y._M_node, true))
-           return difference_type(_S_buffer_size())
-             * (__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first)
-             + (__y._M_last - __y._M_cur);
-
-         return 0;
+         return difference_type(_S_buffer_size())
+           * (__x._M_node - __y._M_node - int(__x._M_node != 0))
+           + (__x._M_cur - __x._M_first)
+           + (__y._M_last - __y._M_cur);
        }
 
       friend _Self