This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: GNU ObjC runtime class table rewritten
- To: Ovidiu Predescu <ovidiu at cup dot hp dot com>
- Subject: Re: GNU ObjC runtime class table rewritten
- From: Nicola Pero <n dot pero at mi dot flashnet dot it>
- Date: Fri, 1 Jun 2001 01:45:57 +0100 (BST)
- Cc: Stan Shebs <shebs at apple dot com>, gcc-patches at gcc dot gnu dot org
- References: <15120.15122.641736.110759@gargle.gargle.HOWL><200105311837.LAA25534@orion.nsr.hp.com>
- Reply-To: n dot pero at mi dot flashnet dot it
Ovidiu> 1. In class_table_insert(), when you insert the node in
Ovidiu> the hash table that already has a linked list for the a
Ovidiu> given index, you can insert it at the beginning of the
Ovidiu> list. Thus you have constant time for insertion.
Ok - been thinking and you are really right - it's stupid to do it the
long way when it's so easy and safe to switch to the short one - here
is the new class_table_insert() - it didn't receive as much testing as
the other one (in particular, I didn't have the time to abuse it with
thread stressing tests) anyway it should work. Please Stan would you
paste this into the class.c file in place of the old
class_table_insert before committing. Thanks Ovidiu for pointing out
the improvement to be made.
/* Insert a class in the table (used when a new class is registered) */
static void
class_table_insert (const char *class_name, Class class_pointer)
{
int hash, length;
class_node_ptr new_node;
/* Find out the class name's hash and length */
CLASS_TABLE_HASH (length, hash, class_name);
/* Prepare the new node holding the class */
new_node = objc_malloc (sizeof (struct class_node));
new_node->name = class_name;
new_node->length = length;
new_node->pointer = class_pointer;
/* Lock the table for modifications */
objc_mutex_lock (__class_table_lock);
/* Insert the new node in the table at the beginning of the table
at class_table_array[hash] */
new_node->next = class_table_array[hash];
class_table_array[hash] = new_node;
objc_mutex_unlock (__class_table_lock);
}