[gcc r16-8178] libstdc++: [_GLIBCXX_DEBUG] Minor optimization on safe iterator detach

Francois Dumont fdumont@gcc.gnu.org
Thu Mar 19 20:57:44 GMT 2026


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

commit r16-8178-gbc9f330ac9e8064c3327f160e22214ff4b2a515e
Author: François Dumont <frs.dumont@gmail.com>
Date:   Mon Mar 16 19:37:50 2026 +0100

    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 equals 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 equals
            to _M_const_local_iterators.
    
    Reviewed-by: Jonathan Wakely <jwakely@redhat.com>

Diff:
---
 libstdc++-v3/src/c++11/debug.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/src/c++11/debug.cc b/libstdc++-v3/src/c++11/debug.cc
index 3e6f286bc0a4..7049d5f1238c 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++-cvs mailing list