[runtime] Avoid equal calls in MonoGHashTable
authorVlad Brezae <brezaevlad@gmail.com>
Fri, 17 Feb 2017 13:37:45 +0000 (15:37 +0200)
committerVlad Brezae <brezaevlad@gmail.com>
Mon, 20 Feb 2017 12:24:25 +0000 (14:24 +0200)
mono_g_hash_table_find_slot is very hot.

mono/metadata/mono-hash.c
mono/metadata/threadpool-io.c

index 6ca6801892d67d87a5d0c4a5858123a0f46db6a9..ba01b92b20316806ebb11200f5f177dcbc0a0da5 100644 (file)
@@ -115,12 +115,21 @@ static inline void mono_g_hash_table_value_store (MonoGHashTable *hash, int slot
 static inline int mono_g_hash_table_find_slot (MonoGHashTable *hash, const MonoObject *key)
 {
        guint i = ((*hash->hash_func) (key)) % hash->table_size;
-       GEqualFunc equal = hash->key_equal_func;
 
-       while (hash->keys [i] && !(*equal) (hash->keys [i], key)) {
-               i++;
-               if (i == hash->table_size)
-                       i = 0;
+       if (hash->key_equal_func) {
+               GEqualFunc equal = hash->key_equal_func;
+
+               while (hash->keys [i] && !(*equal) (hash->keys [i], key)) {
+                       i++;
+                       if (i == hash->table_size)
+                               i = 0;
+               }
+       } else {
+               while (hash->keys [i] && hash->keys [i] != key) {
+                       i++;
+                       if (i == hash->table_size)
+                               i = 0;
+               }
        }
        return i;
 }
@@ -133,8 +142,6 @@ mono_g_hash_table_new_type (GHashFunc hash_func, GEqualFunc key_equal_func, Mono
 
        if (!hash_func)
                hash_func = g_direct_hash;
-       if (!key_equal_func)
-               key_equal_func = g_direct_equal;
 
 #ifdef HAVE_SGEN_GC
        hash = mg_new0 (MonoGHashTable, 1);
index ace9a00bf6a8adb9bd83bcf6944f01bf84cfb882..c5429ffeef16c3faeb4a69b9e54a0001477eaaf5 100644 (file)
@@ -319,7 +319,7 @@ selector_thread (gpointer data)
                return 0;
        }
 
-       states = mono_g_hash_table_new_type (g_direct_hash, g_direct_equal, MONO_HASH_VALUE_GC, MONO_ROOT_SOURCE_THREAD_POOL, "i/o thread pool states table");
+       states = mono_g_hash_table_new_type (g_direct_hash, NULL, MONO_HASH_VALUE_GC, MONO_ROOT_SOURCE_THREAD_POOL, "i/o thread pool states table");
 
        for (;;) {
                gint i, j;