Skip to content

Commit

Permalink
libstdc++: Remove execution branch in deque iterator operator-
Browse files Browse the repository at this point in the history
libstdc++-v3/ChangeLog:

	* include/bits/stl_deque.h
	(std::operator-(deque::iterator, deque::iterator)): Replace if/then with
	a null pointer test.
  • Loading branch information
Dums35 committed Feb 9, 2021
1 parent 790a8e8 commit f6be5d6
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions libstdc++-v3/include/bits/stl_deque.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit f6be5d6

Please sign in to comment.