Skip to content

Commit

Permalink
2003-09-08 Zoltan Varga <vargaz@freemail.hu>
Browse files Browse the repository at this point in the history
	* image.c (load_class_names): Use a temporary hash table to hold the
	namespaces in order to avoid doing many string comparisons.

	* image.h: Fix typo.

	* image.c class.c rawbuffer.c reflection.c threads.c verify.c domain.c:
	Pass NULL instead of g_direct_equal to the GHashTable constructor
	since the NULL case is short-circuited inside g_hash_table_lookup,
	leading to better performance.

svn path=/trunk/mono/; revision=17992
  • Loading branch information
vargaz committed Sep 8, 2003
1 parent fa52b9f commit abca05c
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 31 deletions.
10 changes: 10 additions & 0 deletions mono/metadata/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
2003-09-08 Zoltan Varga <vargaz@freemail.hu>

* image.c (load_class_names): Use a temporary hash table to hold the
namespaces in order to avoid doing many string comparisons.

* image.h: Fix typo.

* image.c class.c rawbuffer.c reflection.c threads.c verify.c domain.c:
Pass NULL instead of g_direct_equal to the GHashTable constructor
since the NULL case is short-circuited inside g_hash_table_lookup,
leading to better performance.

* metadata.c (mono_metadata_custom_attrs_from_index): New function to
obtain the first custom attribute for a given index. Depends on the
CustomAttribute table being sorted by the parent field.
Expand Down
4 changes: 2 additions & 2 deletions mono/metadata/class.c
Original file line number Diff line number Diff line change
Expand Up @@ -1675,7 +1675,7 @@ mono_ptr_class_get (MonoType *type)
mono_loader_lock ();

if (!ptr_hash)
ptr_hash = g_hash_table_new (g_direct_hash, g_direct_equal);
ptr_hash = g_hash_table_new (NULL, NULL);
el_class = mono_class_from_mono_type (type);
if ((result = g_hash_table_lookup (ptr_hash, el_class))) {
mono_loader_unlock ();
Expand Down Expand Up @@ -1716,7 +1716,7 @@ mono_fnptr_class_get (MonoMethodSignature *sig)
mono_loader_lock ();

if (!ptr_hash)
ptr_hash = g_hash_table_new (g_direct_hash, g_direct_equal);
ptr_hash = g_hash_table_new (NULL, NULL);

if ((result = g_hash_table_lookup (ptr_hash, sig))) {
mono_loader_unlock ();
Expand Down
35 changes: 25 additions & 10 deletions mono/metadata/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,11 @@ load_class_names (MonoImage *image)
guint32 cols [MONO_TYPEDEF_SIZE];
const char *name;
const char *nspace;
guint32 i, visib;
guint32 i, visib, nspace_index;
GHashTable *name_cache2, *nspace_table;

/* Temporary hash table to avoid lookups in the nspace_table */
name_cache2 = g_hash_table_new (NULL, NULL);

for (i = 1; i <= t->rows; ++i) {
mono_metadata_decode_row (t, i - 1, cols, MONO_TYPEDEF_SIZE);
Expand All @@ -476,8 +480,19 @@ load_class_names (MonoImage *image)
continue;
name = mono_metadata_string_heap (image, cols [MONO_TYPEDEF_NAME]);
nspace = mono_metadata_string_heap (image, cols [MONO_TYPEDEF_NAMESPACE]);
mono_image_add_to_name_cache (image, nspace, name, i);

nspace_index = cols [MONO_TYPEDEF_NAMESPACE];
nspace_table = g_hash_table_lookup (name_cache2, GUINT_TO_POINTER (nspace_index));
if (!nspace_table) {
nspace_table = g_hash_table_new (g_str_hash, g_str_equal);
g_hash_table_insert (image->name_cache, (char*)nspace, nspace_table);
g_hash_table_insert (name_cache2, GUINT_TO_POINTER (nspace_index),
nspace_table);
}
g_hash_table_insert (nspace_table, (char *) name, GUINT_TO_POINTER (i));
}

g_hash_table_destroy (name_cache2);
}

static void
Expand All @@ -498,8 +513,8 @@ build_guid_table (void)
void
mono_image_init (MonoImage *image)
{
image->method_cache = g_hash_table_new (g_direct_hash, g_direct_equal);
image->class_cache = g_hash_table_new (g_direct_hash, g_direct_equal);
image->method_cache = g_hash_table_new (NULL, NULL);
image->class_cache = g_hash_table_new (NULL, NULL);
image->name_cache = g_hash_table_new (g_str_hash, g_str_equal);
image->array_cache = g_hash_table_new (NULL, NULL);

Expand All @@ -513,11 +528,11 @@ mono_image_init (MonoImage *image)
g_hash_table_new ((GHashFunc)mono_signature_hash,
(GCompareFunc)mono_metadata_signature_equal);

image->runtime_invoke_cache = g_hash_table_new (g_direct_hash, g_direct_equal);
image->managed_wrapper_cache = g_hash_table_new (g_direct_hash, g_direct_equal);
image->native_wrapper_cache = g_hash_table_new (g_direct_hash, g_direct_equal);
image->remoting_invoke_cache = g_hash_table_new (g_direct_hash, g_direct_equal);
image->synchronized_cache = g_hash_table_new (g_direct_hash, g_direct_equal);
image->runtime_invoke_cache = g_hash_table_new (NULL, NULL);
image->managed_wrapper_cache = g_hash_table_new (NULL, NULL);
image->native_wrapper_cache = g_hash_table_new (NULL, NULL);
image->remoting_invoke_cache = g_hash_table_new (NULL, NULL);
image->synchronized_cache = g_hash_table_new (NULL, NULL);

image->generics_cache = g_hash_table_new ((GHashFunc)mono_metadata_type_hash, (GEqualFunc)mono_metadata_type_equal);

Expand Down Expand Up @@ -836,7 +851,7 @@ mono_image_open (const char *fname, MonoImageOpenStatus *status)
}

static void
free_hash_table(gpointer key, gpointer val, gpointer user_data)
free_hash_table (gpointer key, gpointer val, gpointer user_data)
{
g_hash_table_destroy ((GHashTable*)val);
}
Expand Down
2 changes: 1 addition & 1 deletion mono/metadata/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ typedef struct {
struct _MonoImage {
int ref_count;
FILE *f;
/* if f is NULL the image was loaded rom raw data */
/* if f is NULL the image was loaded from raw data */
char *raw_data;
guint32 raw_data_len;
gboolean raw_data_allocated;
Expand Down
2 changes: 1 addition & 1 deletion mono/metadata/rawbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ mono_raw_buffer_init (void)

get_alignment ();

mmap_map = g_hash_table_new (g_direct_hash, g_direct_equal);
mmap_map = g_hash_table_new (NULL, NULL);
}

static void *
Expand Down
28 changes: 14 additions & 14 deletions mono/metadata/reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -2962,10 +2962,10 @@ create_dynamic_mono_image (char *assembly_name, char *module_name)
image->references = g_new0 (MonoAssembly*, 1);
image->references [0] = NULL;

image->method_cache = g_hash_table_new (g_direct_hash, g_direct_equal);
image->class_cache = g_hash_table_new (g_direct_hash, g_direct_equal);
image->method_cache = g_hash_table_new (NULL, NULL);
image->class_cache = g_hash_table_new (NULL, NULL);
image->name_cache = g_hash_table_new (g_str_hash, g_str_equal);
image->array_cache = g_hash_table_new (g_direct_hash, g_direct_equal);
image->array_cache = g_hash_table_new (NULL, NULL);

image->delegate_begin_invoke_cache =
g_hash_table_new ((GHashFunc)mono_signature_hash,
Expand All @@ -2977,11 +2977,11 @@ create_dynamic_mono_image (char *assembly_name, char *module_name)
g_hash_table_new ((GHashFunc)mono_signature_hash,
(GCompareFunc)mono_metadata_signature_equal);

image->runtime_invoke_cache = g_hash_table_new (g_direct_hash, g_direct_equal);
image->managed_wrapper_cache = g_hash_table_new (g_direct_hash, g_direct_equal);
image->native_wrapper_cache = g_hash_table_new (g_direct_hash, g_direct_equal);
image->remoting_invoke_cache = g_hash_table_new (g_direct_hash, g_direct_equal);
image->synchronized_cache = g_hash_table_new (g_direct_hash, g_direct_equal);
image->runtime_invoke_cache = g_hash_table_new (NULL, NULL);
image->managed_wrapper_cache = g_hash_table_new (NULL, NULL);
image->native_wrapper_cache = g_hash_table_new (NULL, NULL);
image->remoting_invoke_cache = g_hash_table_new (NULL, NULL);
image->synchronized_cache = g_hash_table_new (NULL, NULL);

image->generics_cache = g_hash_table_new ((GHashFunc)mono_metadata_type_hash, (GEqualFunc)mono_metadata_type_equal);

Expand Down Expand Up @@ -3016,12 +3016,12 @@ mono_image_basic_init (MonoReflectionAssemblyBuilder *assemblyb)

assembly->assembly.dynamic = assembly;
assemblyb->assembly.assembly = (MonoAssembly*)assembly;
assembly->token_fixups = mono_g_hash_table_new (g_direct_hash, g_direct_equal);
assembly->method_to_table_idx = mono_g_hash_table_new (g_direct_hash, g_direct_equal);
assembly->field_to_table_idx = mono_g_hash_table_new (g_direct_hash, g_direct_equal);
assembly->param_marshalling = mono_g_hash_table_new (g_direct_hash, g_direct_equal);
assembly->handleref = g_hash_table_new (g_direct_hash, g_direct_equal);
assembly->tokens = mono_g_hash_table_new (g_direct_hash, g_direct_equal);
assembly->token_fixups = mono_g_hash_table_new (NULL, NULL);
assembly->method_to_table_idx = mono_g_hash_table_new (NULL, NULL);
assembly->field_to_table_idx = mono_g_hash_table_new (NULL, NULL);
assembly->param_marshalling = mono_g_hash_table_new (NULL, NULL);
assembly->handleref = g_hash_table_new (NULL, NULL);
assembly->tokens = mono_g_hash_table_new (NULL, NULL);
assembly->typeref = g_hash_table_new ((GHashFunc)mono_metadata_type_hash, (GCompareFunc)mono_metadata_type_equal);
assembly->blob_cache = mono_g_hash_table_new ((GHashFunc)mono_blob_entry_hash, (GCompareFunc)mono_blob_entry_equal);

Expand Down
2 changes: 1 addition & 1 deletion mono/metadata/threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ static void handle_store(MonoThread *thread)
#endif

if(threads==NULL) {
threads=mono_g_hash_table_new(g_direct_hash, g_direct_equal);
threads=mono_g_hash_table_new(NULL, NULL);
}

/* We don't need to duplicate thread->handle, because it is
Expand Down
4 changes: 2 additions & 2 deletions mono/metadata/verify.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ verify_constant_table (MonoImage *image, GSList *list, int level)
MonoTableInfo *t = &image->tables [MONO_TABLE_CONSTANT];
guint32 cols [MONO_CONSTANT_SIZE];
guint32 value, i;
GHashTable *dups = g_hash_table_new (g_direct_hash, g_direct_equal);
GHashTable *dups = g_hash_table_new (NULL, NULL);

for (i = 0; i < t->rows; ++i) {
mono_metadata_decode_row (t, i, cols, MONO_CONSTANT_SIZE);
Expand Down Expand Up @@ -388,7 +388,7 @@ verify_event_map_table (MonoImage *image, GSList *list, int level)
MonoTableInfo *t = &image->tables [MONO_TABLE_EVENTMAP];
guint32 cols [MONO_EVENT_MAP_SIZE];
guint32 i, last_event;
GHashTable *dups = g_hash_table_new (g_direct_hash, g_direct_equal);
GHashTable *dups = g_hash_table_new (NULL, NULL);

last_event = 0;

Expand Down

0 comments on commit abca05c

Please sign in to comment.