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: [RFC] Long standing small inefficiency in std::deque


... this is the patch. Tested x86_64-linux.

Paolo.

////////////////
2007-11-13  Paolo Carlini  <pcarlini@suse.de>

	* include/bits/deque.tcc (deque<>::_M_push_back_aux,
	_M_push_front_aux): Do not copy unnecessarily to __t_copy.
Index: include/bits/deque.tcc
===================================================================
--- include/bits/deque.tcc	(revision 130102)
+++ include/bits/deque.tcc	(working copy)
@@ -350,21 +350,22 @@
       void
       deque<_Tp, _Alloc>::
       _M_push_back_aux(_Args&&... __args)
-      {
-	value_type __t_copy(std::forward<_Args>(__args)...);
 #else
       void
       deque<_Tp, _Alloc>::
       _M_push_back_aux(const value_type& __t)
-      {
-	value_type __t_copy = __t;
 #endif
+      {
 	_M_reserve_map_at_back();
 	*(this->_M_impl._M_finish._M_node + 1) = this->_M_allocate_node();
 	try
 	  {
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
 	    this->_M_impl.construct(this->_M_impl._M_finish._M_cur,
-				    _GLIBCXX_MOVE(__t_copy));
+				    std::forward<_Args>(__args)...);
+#else
+	    this->_M_impl.construct(this->_M_impl._M_finish._M_cur, __t);
+#endif
 	    this->_M_impl._M_finish._M_set_node(this->_M_impl._M_finish._M_node
 						+ 1);
 	    this->_M_impl._M_finish._M_cur = this->_M_impl._M_finish._M_first;
@@ -383,15 +384,12 @@
       void
       deque<_Tp, _Alloc>::
       _M_push_front_aux(_Args&&... __args)
-      {
-	value_type __t_copy(std::forward<_Args>(__args)...);
 #else
       void
       deque<_Tp, _Alloc>::
       _M_push_front_aux(const value_type& __t)
-      {
-	value_type __t_copy = __t;
 #endif
+      {
 	_M_reserve_map_at_front();
 	*(this->_M_impl._M_start._M_node - 1) = this->_M_allocate_node();
 	try
@@ -399,8 +397,12 @@
 	    this->_M_impl._M_start._M_set_node(this->_M_impl._M_start._M_node
 					       - 1);
 	    this->_M_impl._M_start._M_cur = this->_M_impl._M_start._M_last - 1;
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
 	    this->_M_impl.construct(this->_M_impl._M_start._M_cur,
-				    _GLIBCXX_MOVE(__t_copy));
+				    std::forward<_Args>(__args)...);
+#else
+	    this->_M_impl.construct(this->_M_impl._M_start._M_cur, __t);
+#endif
 	  }
 	catch(...)
 	  {

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