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]

[Patch] Streamline a bit __mt_alloc::allocate


Hi,

duplicated code was lurking in the tangle of #ifdefs... ;)

Tested x86/x86_64-linux, chech/check-performance, will commit tomorrow.

Paolo.

/////////////
2004-04-03  Paolo Carlini  <pcarlini@suse.de>

	* include/ext/mt_allocator.h (__mt_alloc<>::allocate):
	Factor out some duplicated code.
diff -urN libstdc++-v3-orig/include/ext/mt_allocator.h libstdc++-v3/include/ext/mt_allocator.h
--- libstdc++-v3-orig/include/ext/mt_allocator.h	2004-04-02 18:58:09.000000000 +0200
+++ libstdc++-v3/include/ext/mt_allocator.h	2004-04-03 01:30:20.000000000 +0200
@@ -359,14 +359,6 @@
 		    }
 		  __gthread_mutex_unlock(__bin._M_mutex);
 		}
-	      
-	      // Return the first newly added block in our list and
-	      // update the counters
-	      __block = __bin._M_first[__thread_id];
-	      __bin._M_first[__thread_id] = __bin._M_first[__thread_id]->_M_next;
-	      __block->_M_thread_id = __thread_id;
-	      --__bin._M_free[__thread_id];
-	      ++__bin._M_used[__thread_id];
 	    }
 	  else
 #endif
@@ -384,28 +376,20 @@
 		  --__block_count;
 		}
 	      __block->_M_next = NULL;
-	      
-	      // Remove from list.
-	      __block = __bin._M_first[0];
-	      __bin._M_first[0] = __bin._M_first[0]->_M_next;
 	    }
 	}
-      else
-	{
-	  // "Default" operation - we have blocks on our own freelist
-	  // grab the first record and update the counters.
-	  __block = __bin._M_first[__thread_id];
-	  __bin._M_first[__thread_id] = __bin._M_first[__thread_id]->_M_next;
 
+      __block = __bin._M_first[__thread_id];
+      __bin._M_first[__thread_id] = __bin._M_first[__thread_id]->_M_next;
 #ifdef __GTHREADS
-	  if (__gthread_active_p())
-	    {
-	      __block->_M_thread_id = __thread_id;
-	      --__bin._M_free[__thread_id];
-	      ++__bin._M_used[__thread_id];
-	    }
-#endif
+      if (__gthread_active_p())
+	{
+	  __block->_M_thread_id = __thread_id;
+	  --__bin._M_free[__thread_id];
+	  ++__bin._M_used[__thread_id];
 	}
+#endif
+
       char* __c = reinterpret_cast<char*>(__block) + sizeof(_Block_record);
       return static_cast<_Tp*>(static_cast<void*>(__c));
     }

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