[gcc r11-7157] libstdc++: Remove execution branch in deque iterator operator-

Franथईois Dumont fdumont@gcc.gnu.org
Tue Feb 9 20:56:49 GMT 2021


https://gcc.gnu.org/g:f6be5d6ee31b76838e242704782938bc9745659c

commit r11-7157-gf6be5d6ee31b76838e242704782938bc9745659c
Author: François Dumont <fdumont@gcc.gnu.org>
Date:   Thu Feb 4 06:45:18 2021 +0100

    libstdc++: Remove execution branch in deque iterator operator-
    
    libstdc++-v3/ChangeLog:
    
            * include/bits/stl_deque.h
            (std::operator-(deque::iterator, deque::iterator)): Replace if/then with
            a null pointer test.

Diff:
---
 libstdc++-v3/include/bits/stl_deque.h | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/libstdc++-v3/include/bits/stl_deque.h b/libstdc++-v3/include/bits/stl_deque.h
index 04b70b77621..8bba7a3740f 100644
--- a/libstdc++-v3/include/bits/stl_deque.h
+++ b/libstdc++-v3/include/bits/stl_deque.h
@@ -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


More information about the Libstdc++-cvs mailing list