+/*
+ * find_cached_memberref_sig:
+ *
+ * Return a cached copy of the memberref signature identified by SIG_IDX.
+ * We use a gpointer since the cache stores both MonoTypes and MonoMethodSignatures.
+ * A cache is needed since the type/signature parsing routines allocate everything
+ * from a mempool, so without a cache, multiple requests for the same signature would
+ * lead to unbounded memory growth. For normal methods/fields this is not a problem
+ * since the resulting methods/fields are cached, but inflated methods/fields cannot
+ * be cached.
+ * LOCKING: Acquires the loader lock.
+ */
+static gpointer
+find_cached_memberref_sig (MonoImage *image, guint32 sig_idx)
+{
+ gpointer res;
+
+ mono_loader_lock ();
+ res = g_hash_table_lookup (image->memberref_signatures, GUINT_TO_POINTER (sig_idx));
+ mono_loader_unlock ();
+
+ return res;
+}
+
+static gpointer
+cache_memberref_sig (MonoImage *image, guint32 sig_idx, gpointer sig)
+{
+ gpointer prev_sig;
+
+ mono_loader_lock ();
+ prev_sig = g_hash_table_lookup (image->memberref_signatures, GUINT_TO_POINTER (sig_idx));
+ if (prev_sig) {
+ /* Somebody got in before us */
+ sig = prev_sig;
+ }
+ else
+ g_hash_table_insert (image->memberref_signatures, GUINT_TO_POINTER (sig_idx), sig);
+ mono_loader_unlock ();
+
+ return sig;
+}
+