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]

Re: [Patch] libstdc++/23425


chris jefferson wrote:

>Sorry, I meant when the loop isn't removed because _Destroy has to
>actually do something, then vector is slightly slower and deque is
>slightly faster (of course if that "doing something" isn't
>super-trivial, like just maintaining a reference count or something,
>then the extra tiny loop overhead gets quickly swamped away).
>  
>
Ok. No confusions, anyway, I was really asking whether the current
optimizers are basically able to deal perfectly with the
trivial_destructor case, eventually producing the same code that could
be obtained if we had a perfect type_traits to begin with. In case of
vector, to be sure, not deque.

Anyway, the attached will help further playing with the idea ;)

Paolo.

///////////////
Index: include/bits/stl_construct.h
===================================================================
--- include/bits/stl_construct.h	(revision 106359)
+++ include/bits/stl_construct.h	(working copy)
@@ -108,6 +108,37 @@
 
   /**
    * @if maint
+   * This is a helper function used only by __destroy_aux().
+   * @endif
+   */
+  template<typename _RandomIterator>
+    inline void
+    __destroy_aux_2(_RandomIterator __first, _RandomIterator __last,
+		    std::random_access_iterator_tag)
+    {
+      typename iterator_traits<_RandomIterator>::difference_type __diff =
+	__last - __first;
+
+      for (; __diff > 0; --__diff, ++__first)
+	std::_Destroy(&*__first);
+    }
+  
+  /**
+   * @if maint
+   * This is a helper function used only by __destroy_aux().
+   * @endif
+   */
+  template<typename _ForwardIterator>
+    inline void
+    __destroy_aux_2(_ForwardIterator __first, _ForwardIterator __last,
+		    std::forward_iterator_tag)
+    {
+      for (; __first != __last; ++__first)
+	std::_Destroy(&*__first);
+    }
+
+  /**
+   * @if maint
    * Destroy a range of objects with nontrivial destructors.
    *
    * This is a helper function used only by _Destroy().
@@ -117,9 +148,8 @@
     inline void
     __destroy_aux(_ForwardIterator __first, _ForwardIterator __last,
 		  __false_type)
-    {
-      for (; __first != __last; ++__first)
-	std::_Destroy(&*__first);
+    { 
+      std::__destroy_aux_2(__first, __last, std::__iterator_category(__first));
     }
 
   /**

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