[gobject-introspection/wip/carlosg/cache-misses] girepository: Also store GType cache misses
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection/wip/carlosg/cache-misses] girepository: Also store GType cache misses
- Date: Wed, 13 Nov 2019 19:02:47 +0000 (UTC)
commit d908039aca36ddb13068600ce3df7ad0c943ea09
Author: Carlos Garnacho <carlosg gnome org>
Date: Wed Nov 13 19:37:00 2019 +0100
girepository: Also store GType cache misses
There are notably 3 classes of GTypes where a girepository lookup
might fail:
- GTypes from private interfaces in public objects (eg. MetaCullable in
mutter)
- GTypes for private base objects with public interfaces (eg. GLocalFile
in GLib)
- GTypes registered from the language, and presumably not coming from the
GIR
It is moot to look for those over and over again, and a full lookup can
be taxing if looking up for a method/property on objects with those
characteristics.
It seems we can cache the misses too, so next lookups are just as quick
as an introspected GType.
girepository/girepository.c | 28 ++++++++++++++++++++++------
1 file changed, 22 insertions(+), 6 deletions(-)
---
diff --git a/girepository/girepository.c b/girepository/girepository.c
index fd668c5a..90045540 100644
--- a/girepository/girepository.c
+++ b/girepository/girepository.c
@@ -120,6 +120,13 @@ DllMain (HINSTANCE hinstDLL,
#endif
+static void
+check_base_info_unref (GIBaseInfo *base_info)
+{
+ if (base_info)
+ g_base_info_unref (base_info);
+}
+
static void
g_irepository_init (GIRepository *repository)
{
@@ -135,7 +142,7 @@ g_irepository_init (GIRepository *repository)
repository->priv->info_by_gtype
= g_hash_table_new_full (g_direct_hash, g_direct_equal,
(GDestroyNotify) NULL,
- (GDestroyNotify) g_base_info_unref);
+ (GDestroyNotify) check_base_info_unref);
repository->priv->info_by_error_domain
= g_hash_table_new_full (g_direct_hash, g_direct_equal,
(GDestroyNotify) NULL,
@@ -808,11 +815,15 @@ g_irepository_find_by_gtype (GIRepository *repository,
repository = get_repository (repository);
- cached = g_hash_table_lookup (repository->priv->info_by_gtype,
- (gpointer)gtype);
+ if (g_hash_table_lookup_extended (repository->priv->info_by_gtype,
+ (gpointer)gtype,
+ NULL, (gpointer*)&cached))
+ {
+ if (!cached)
+ return NULL;
- if (cached != NULL)
- return g_base_info_ref (cached);
+ return g_base_info_ref (cached);
+ }
data.gtype_name = g_type_name (gtype);
data.result_typelib = NULL;
@@ -849,7 +860,12 @@ g_irepository_find_by_gtype (GIRepository *repository,
g_base_info_ref (cached));
return cached;
}
- return NULL;
+ else
+ {
+ g_hash_table_insert (repository->priv->info_by_gtype,
+ (gpointer) gtype, NULL);
+ return NULL;
+ }
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]