+static void
+free_inflated_signature (MonoInflatedMethodSignature *sig)
+{
+ mono_metadata_free_inflated_signature (sig->sig);
+ g_free (sig);
+}
+
+/*
+ * LOCKING: assumes the loader lock is held.
+ */
+MonoMethodInflated*
+mono_method_inflated_lookup (MonoMethodInflated* method, gboolean cache)
+{
+ if (cache) {
+ if (!generic_method_cache)
+ generic_method_cache = g_hash_table_new_full (inflated_method_hash, inflated_method_equal, NULL, (GDestroyNotify)free_inflated_method);
+ g_hash_table_insert (generic_method_cache, method, method);
+ return method;
+ } else {
+ if (generic_method_cache)
+ return g_hash_table_lookup (generic_method_cache, method);
+ return NULL;
+ }
+}
+
+/*
+ * mono_metadata_get_inflated_signature:
+ *
+ * Given an inflated signature and a generic context, return a canonical copy of the
+ * signature. The returned signature might be equal to SIG or it might be a cached copy.
+ */
+MonoMethodSignature *
+mono_metadata_get_inflated_signature (MonoMethodSignature *sig, MonoGenericContext *context)
+{
+ MonoInflatedMethodSignature helper;
+ MonoInflatedMethodSignature *res;
+
+ mono_loader_lock ();
+ if (!generic_signature_cache)
+ generic_signature_cache = g_hash_table_new_full (inflated_signature_hash, inflated_signature_equal, NULL, (GDestroyNotify)free_inflated_signature);
+
+ helper.sig = sig;
+ helper.context.class_inst = context->class_inst;
+ helper.context.method_inst = context->method_inst;
+ res = g_hash_table_lookup (generic_signature_cache, &helper);
+ if (!res) {
+ res = g_new0 (MonoInflatedMethodSignature, 1);
+ res->sig = sig;
+ res->context.class_inst = context->class_inst;
+ res->context.method_inst = context->method_inst;
+ g_hash_table_insert (generic_signature_cache, res, res);
+ }
+
+ mono_loader_unlock ();
+ return res->sig;
+}
+