This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[Patch] Streamline a bit __mt_alloc::allocate
- From: Paolo Carlini <pcarlini at suse dot de>
- To: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Sat, 03 Apr 2004 01:36:02 +0200
- Subject: [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));
}