This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[v3] Trivial clean-up to mt_allocator
- From: Paolo Carlini <pcarlini at suse dot de>
- To: "'gcc-patches at gcc dot gnu dot org'" <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 24 Mar 2004 15:42:14 +0100
- Subject: [v3] Trivial clean-up to mt_allocator
Hi,
something trivial that I have noticed while studying in detail this code.
Tested check/check-performance on x86-linux (--enable-libstdcxx-allocator=mt
of course).
Paolo.
///////////////
2004-03-24 Paolo Carlini <pcarlini@suse.de>
* include/ext/mt_allocator.h (__mt_alloc<>::allocate,
__mt_alloc<>::deallocate): Avoid redundant conditionals.
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-03-12 22:11:51.000000000 +0100
+++ libstdc++-v3/include/ext/mt_allocator.h 2004-03-24 14:40:44.000000000 +0100
@@ -353,16 +353,8 @@
tmp = __bin.first[0]->next;
block = __bin.first[0];
- if (__bin.first[__thread_id] == NULL)
- {
- __bin.first[__thread_id] = block;
- block->next = NULL;
- }
- else
- {
- block->next = __bin.first[__thread_id];
- __bin.first[__thread_id] = block;
- }
+ block->next = __bin.first[__thread_id];
+ __bin.first[__thread_id] = block;
block->thread_id = __thread_id;
__bin.free[__thread_id]++;
@@ -466,16 +458,8 @@
while (remove > 0)
{
tmp = __bin.first[thread_id]->next;
- if (__bin.first[0] == NULL)
- {
- __bin.first[0] = __bin.first[thread_id];
- __bin.first[0]->next = NULL;
- }
- else
- {
- __bin.first[thread_id]->next = __bin.first[0];
- __bin.first[0] = __bin.first[thread_id];
- }
+ __bin.first[thread_id]->next = __bin.first[0];
+ __bin.first[0] = __bin.first[thread_id];
__bin.first[thread_id] = tmp;
__bin.free[thread_id]--;
@@ -486,41 +470,20 @@
// Return this block to our list and update counters and
// owner id as needed.
- if (__bin.first[thread_id] == NULL)
- {
- __bin.first[thread_id] = block;
- block->next = NULL;
- }
- else
- {
- block->next = __bin.first[thread_id];
- __bin.first[thread_id] = block;
- }
+ block->next = __bin.first[thread_id];
+ __bin.first[thread_id] = block;
__bin.free[thread_id]++;
- if (thread_id == block->thread_id)
- __bin.used[thread_id]--;
- else
- {
- __bin.used[block->thread_id]--;
- block->thread_id = thread_id;
- }
+ __bin.used[block->thread_id]--;
+ block->thread_id = thread_id;
}
else
#endif
{
// Single threaded application - return to global pool.
- if (__bin.first[0] == NULL)
- {
- __bin.first[0] = block;
- block->next = NULL;
- }
- else
- {
- block->next = __bin.first[0];
- __bin.first[0] = block;
- }
+ block->next = __bin.first[0];
+ __bin.first[0] = block;
}
}