[evince: 8/13] libdocument: Don't store the GTypeModule in the EvBackendInfo
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince: 8/13] libdocument: Don't store the GTypeModule in the EvBackendInfo
- Date: Mon, 4 Jun 2012 10:30:21 +0000 (UTC)
commit faddc075ba3cd9dc875363738fc91bd1da4bcbd1
Author: Christian Persch <chpe gnome org>
Date: Sat Mar 27 16:11:31 2010 +0100
libdocument: Don't store the GTypeModule in the EvBackendInfo
Don't keep non-constant data in EvBackendInfo. This will make it easy
to later add a module cache.
libdocument/ev-backend-info.h | 3 ---
libdocument/ev-document-factory.c | 30 ++++++++++++++++++++++--------
2 files changed, 22 insertions(+), 11 deletions(-)
---
diff --git a/libdocument/ev-backend-info.h b/libdocument/ev-backend-info.h
index 9b7ef49..27737d0 100644
--- a/libdocument/ev-backend-info.h
+++ b/libdocument/ev-backend-info.h
@@ -26,8 +26,6 @@
#include <glib.h>
-#include "ev-module.h"
-
G_BEGIN_DECLS
typedef struct _EvBackendInfo EvBackendInfo;
@@ -40,7 +38,6 @@ struct _EvBackendInfo {
volatile int ref_count;
gchar *module_name;
- GTypeModule *module;
gboolean resident;
};
diff --git a/libdocument/ev-document-factory.c b/libdocument/ev-document-factory.c
index 1c0a735..3e8fd6d 100644
--- a/libdocument/ev-document-factory.c
+++ b/libdocument/ev-document-factory.c
@@ -41,6 +41,7 @@
#define BACKEND_DATA_KEY "ev-backend-info"
static GList *ev_backends_list = NULL;
+static GHashTable *ev_module_hash = NULL;
static gchar *ev_backends_dir = NULL;
static EvDocument* ev_document_factory_new_document_for_mime_type (const char *mime_type,
@@ -82,6 +83,7 @@ ev_document_factory_new_document_for_mime_type (const gchar *mime_type,
{
EvDocument *document;
EvBackendInfo *info;
+ GTypeModule *module = NULL;
g_return_val_if_fail (mime_type != NULL, NULL);
@@ -104,29 +106,36 @@ ev_document_factory_new_document_for_mime_type (const gchar *mime_type,
return NULL;
}
- if (!info->module) {
+ if (ev_module_hash != NULL) {
+ module = g_hash_table_lookup (ev_module_hash, info->module_name);
+ }
+ if (module == NULL) {
gchar *path;
path = g_module_build_path (ev_backends_dir, info->module_name);
- info->module = G_TYPE_MODULE (_ev_module_new (path, info->resident));
+ module = G_TYPE_MODULE (_ev_module_new (path, info->resident));
g_free (path);
+
+ if (ev_module_hash == NULL) {
+ ev_module_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
+ g_free,
+ NULL /* leaked on purpose */);
+ }
+ g_hash_table_insert (ev_module_hash, g_strdup (info->module_name), module);
}
- if (!g_type_module_use (info->module)) {
+ if (!g_type_module_use (module)) {
const char *err;
err = g_module_error ();
g_set_error (error, EV_DOCUMENT_ERROR, EV_DOCUMENT_ERROR_INVALID,
"Failed to load backend for '%s': %s",
mime_type, err ? err : "unknown error");
- g_object_unref (G_OBJECT (info->module));
- info->module = NULL;
-
return NULL;
}
- document = EV_DOCUMENT (_ev_module_new_object (EV_MODULE (info->module)));
- g_type_module_unuse (info->module);
+ document = EV_DOCUMENT (_ev_module_new_object (EV_MODULE (module)));
+ g_type_module_unuse (module);
g_object_set_data_full (G_OBJECT (document), BACKEND_DATA_KEY,
_ev_backend_info_ref (info),
@@ -251,6 +260,11 @@ _ev_document_factory_shutdown (void)
g_list_free (ev_backends_list);
ev_backends_list = NULL;
+ if (ev_module_hash != NULL) {
+ g_hash_table_unref (ev_module_hash);
+ ev_module_hash = NULL;
+ }
+
g_free (ev_backends_dir);
ev_backends_dir = NULL;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]