[PATCH][_GLIBCXX_DEBUG] Minor optimization

François Dumont frs.dumont@gmail.com
Thu Mar 19 18:05:24 GMT 2026


Hi

May be something that I should have committed as trivial but it's also 
trivial to review.

     libstdc++: [_GLIBCXX_DEBUG] Minor optimization on safe iterator detach

     An iterator cannot be at the same time const and mutable so it 
cannot be
     at the same time in both list of iterators maintained at debug 
container
     level.

     libstdc++-v3/ChangeLog:

             * src/c++11/debug.cc 
(_Safe_sequence_base::_M_detach_single): Do not
             check if input iterator is equal to _M_iterators if already 
equal to
              _M_const_iterators.
(_Safe_unordered_container_base::_M_detach_local_single): Do not check
             if input local iterator is equal to _M_local_iterators if 
already equal
             to _M_const_local_iterators.

Ok to commit ?

François

-------------- next part --------------
diff --git a/libstdc++-v3/src/c++11/debug.cc b/libstdc++-v3/src/c++11/debug.cc
index 3e6f286bc0a..7049d5f1238 100644
--- a/libstdc++-v3/src/c++11/debug.cc
+++ b/libstdc++-v3/src/c++11/debug.cc
@@ -462,7 +462,7 @@ namespace __gnu_debug
     __it->_M_unlink();
     if (_M_const_iterators == __it)
       _M_const_iterators = __it->_M_next;
-    if (_M_iterators == __it)
+    else if (_M_iterators == __it)
       _M_iterators = __it->_M_next;
   }
 
@@ -711,7 +711,7 @@ namespace __gnu_debug
     __it->_M_unlink();
     if (_M_const_local_iterators == __it)
       _M_const_local_iterators = __it->_M_next;
-    if (_M_local_iterators == __it)
+    else if (_M_local_iterators == __it)
       _M_local_iterators = __it->_M_next;
   }
 


More information about the Libstdc++ mailing list