This is the mail archive of the mailing list for the GCC project.

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

Re: GNU ObjC runtime class table rewritten

    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);

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