Simplify __gnu_debug::__foreign_iterator3

Message ID b8b93771-b9e6-ea06-594a-924bc92c266d@gmail.com
State New
Headers show
Series
  • Simplify __gnu_debug::__foreign_iterator3
Related show

Commit Message

François Dumont Sept. 28, 2018, 8:25 p.m.
Committed as trivial.

The main reason I am fixing this is that:

       if (__it._M_get_sequence()->begin() == __it._M_get_sequence()->end())

is generating safe iterators to check for an empty sequence. Doing so it 
locks the mutex to link the iterator so quite an expensive operation 
compared to calling empty().

2018-09-28  François Dumont  <fdumont@gcc.gnu.org>

     * include/debug/functions.h
     (__foreign_iterator_aux3(const _Safe_iterator<>&, const _InputeIter&,
     const _InputIter&, __true_type)): Use empty() rather than begin() ==
     end().

François

Patch

diff --git a/libstdc++-v3/include/debug/functions.h b/libstdc++-v3/include/debug/functions.h
index 21b60df16ed..13059bbf463 100644
--- a/libstdc++-v3/include/debug/functions.h
+++ b/libstdc++-v3/include/debug/functions.h
@@ -123,7 +123,7 @@  namespace __gnu_debug
     {
       if (__other == __other_end)
 	return true;  // inserting nothing is safe even if not foreign iters
-      if (__it._M_get_sequence()->begin() == __it._M_get_sequence()->end())
+      if (__it._M_get_sequence()->empty())
 	return true;  // can't be self-inserting if self is empty
       return __foreign_iterator_aux4(__it, std::__addressof(*__other));
     }