This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

unsafe STL patch


Hello

   This is a patch proposition to:
- Limit impact on STL safe mode on performance
- Limit template method instanciation

My point is that once an iterator range has been validated thanks to the check_valid_range or any similar function it is useless to keep the safe wrapper when passing it to the normal container implementation. Of course the safe wrapper can only be removed if the check_valid_range has been able to validate that begin is before end which is only possible for random access iterator.

The patch is limited to the impact on the list safe implementation. If you find an interest in this patch I will generalize it to other safe containers, complete ChangeLog and perhaps fill a FSF form.

Best
Index: functions.h
===================================================================
--- functions.h	(révision 156260)
+++ functions.h	(copie de travail)
@@ -34,6 +34,7 @@
 #include <cstddef>                       // for ptrdiff_t
 #include <bits/stl_iterator_base_types.h> // for iterator_traits, categories
 #include <bits/cpp_type_traits.h>         // for __is_integer
+#include <ext/type_traits.h>              // for enable_if
 
 namespace __gnu_debug
 {
@@ -378,6 +379,22 @@
 	++__first;
       return __first == __last;
     }
+
+  template<typename _Iterator>
+    inline _Iterator
+    __unsafe(_Iterator __it)
+    { return __it; }
+
+
+  template<typename _Iterator, typename _Sequence>
+    inline typename
+    __gnu_cxx::__enable_if<std::__are_same<
+            std::random_access_iterator_tag,
+            typename std::iterator_traits<_Iterator>::iterator_category>::value,
+                           _Iterator>::type
+    __unsafe(const _Safe_iterator<_Iterator, _Sequence>& __x)
+    { return __x.base(); }
+
 } // namespace __gnu_debug
 
 #endif
Index: list
===================================================================
--- list	(révision 156260)
+++ list	(copie de travail)
@@ -78,7 +78,8 @@
       template<class _InputIterator>
       list(_InputIterator __first, _InputIterator __last,
 	   const _Allocator& __a = _Allocator())
-      : _Base(__gnu_debug::__check_valid_range(__first, __last), __last, __a)
+      : _Base(__gnu_debug::__unsafe(__gnu_debug::__check_valid_range(__first, __last)),
+              __gnu_debug::__unsafe(__last), __a)
       { }
 
 
@@ -139,8 +140,8 @@
         void
         assign(_InputIterator __first, _InputIterator __last)
         {
-	  __glibcxx_check_valid_range(__first, __last);
-	  _Base::assign(__first, __last);
+          __glibcxx_check_valid_range(__first, __last);
+          _Base::assign(__gnu_debug::__unsafe(__first), __gnu_debug::__unsafe(__last));
 	  this->_M_invalidate_all();
 	}
 
@@ -341,9 +342,10 @@
         insert(iterator __position, _InputIterator __first,
 	       _InputIterator __last)
         {
-	  __glibcxx_check_insert_range(__position, __first, __last);
-	  _Base::insert(__position.base(), __first, __last);
-	}
+          __glibcxx_check_insert_range(__position, __first, __last);
+          _Base::insert(__position.base(), __gnu_debug::__unsafe(__first),
+                                           __gnu_debug::__unsafe(__last));
+        }
 
       iterator
       erase(iterator __position)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]