darling-libobjc2/class_table.c
theraven bdf97cf64e Added hopscotch table implementation and rewrote the class table to use it. This is done so that the class table and protocol tables can share the same code (currently there is no protocol table).
Note that concurrent resizing has not yet been implemented.  That means that there is a hard limit on the number of classes that can be loaded.  This is currently set to quite a small number for testing, to stress the hash table.  If you're experiencing problems as a result, then please let me know and I will increase it.
2010-01-07 18:22:13 +00:00

51 lines
1.2 KiB
C

#include "objc/objc-api.h"
#include "lock.h"
#include <stdlib.h>
// Get the functions for string hashing
#include "string_hash.h"
static int class_compare(const char *name, const Class class)
{
return string_compare(name, class->name);
}
static int class_hash(const Class class)
{
return string_hash(class->name);
}
#define MAP_TABLE_NAME class_table_internal
#define MAP_TABLE_COMPARE_FUNCTION class_compare
#define MAP_TABLE_HASH_KEY string_hash
#define MAP_TABLE_HASH_VALUE class_hash
// This defines the maximum number of classes that the runtime supports.
#define MAP_TABLE_STATIC_SIZE 2048
#include "hash_table.h"
static class_table_internal_table class_table;
static mutex_t class_table_lock;
void class_table_insert(Class class)
{
class_table_internal_insert(&class_table, class->name, class);
}
Class class_table_get_safe(const char *class_name)
{
return class_table_internal_table_get(&class_table, class_name);
}
Class
class_table_next (void **e)
{
return class_table_internal_next(&class_table,
(struct class_table_internal_table_enumerator**)e);
}
void __objc_init_class_tables(void)
{
LOCK(__objc_runtime_mutex);
INIT_LOCK(class_table_lock);
UNLOCK(__objc_runtime_mutex);
}