gst/gstregistryxml.c: If compiling against GLib-2.8 or newer, try to read the registry file using GMappedFile first b...

Original commit message from CVS:
* gst/gstregistryxml.c: (gst_registry_xml_read_cache):
If compiling against GLib-2.8 or newer, try to read the
registry file using GMappedFile first before falling back
to fopen() + fread() (#332151).
This commit is contained in:
Tim-Philipp Müller 2006-03-23 11:54:51 +00:00
parent 2c2fdbf7da
commit a1e4bb5d04
2 changed files with 48 additions and 13 deletions

View file

@ -1,3 +1,10 @@
2006-03-23 Tim-Philipp Müller <tim at centricular dot net>
* gst/gstregistryxml.c: (gst_registry_xml_read_cache):
If compiling against GLib-2.8 or newer, try to read the
registry file using GMappedFile first before falling back
to fopen() + fread() (#332151).
2006-03-22 Wim Taymans <wim@fluendo.com>
* gst/gstinfo.c: (gst_debug_set_active),

View file

@ -466,12 +466,15 @@ load_plugin (xmlTextReaderPtr reader, GList ** feature_list)
gboolean
gst_registry_xml_read_cache (GstRegistry * registry, const char *location)
{
#if GLIB_CHECK_VERSION(2,8,0)
GMappedFile *mapped = NULL;
#endif
GTimer *timer;
gdouble seconds;
xmlTextReaderPtr reader;
xmlTextReaderPtr reader = NULL;
int ret;
gboolean in_registry = FALSE;
FILE *file;
FILE *file = NULL;
/* make sure these types exist */
GST_TYPE_ELEMENT_FACTORY;
@ -480,17 +483,31 @@ gst_registry_xml_read_cache (GstRegistry * registry, const char *location)
timer = g_timer_new ();
file = fopen (location, "r");
if (file == NULL) {
g_timer_destroy (timer);
return FALSE;
#if GLIB_CHECK_VERSION(2,8,0)
mapped = g_mapped_file_new (location, FALSE, NULL);
if (mapped) {
reader = xmlReaderForMemory (g_mapped_file_get_contents (mapped),
g_mapped_file_get_length (mapped), NULL, NULL, 0);
if (reader == NULL) {
g_mapped_file_free (mapped);
mapped = NULL;
}
}
#endif
reader = xmlReaderForFd (fileno (file), NULL, NULL, 0);
if (!reader) {
fclose (file);
g_timer_destroy (timer);
return FALSE;
if (reader == NULL) {
file = fopen (location, "r");
if (file == NULL) {
g_timer_destroy (timer);
return FALSE;
}
reader = xmlReaderForFd (fileno (file), NULL, NULL, 0);
if (!reader) {
fclose (file);
g_timer_destroy (timer);
return FALSE;
}
}
while ((ret = xmlTextReaderRead (reader)) == 1) {
@ -523,7 +540,12 @@ gst_registry_xml_read_cache (GstRegistry * registry, const char *location)
xmlFreeTextReader (reader);
if (ret != 0) {
GST_ERROR ("parsing registry cache: %s", location);
fclose (file);
#if GLIB_CHECK_VERSION(2,8,0)
if (mapped)
g_mapped_file_free (mapped);
#endif
if (file)
fclose (file);
g_timer_destroy (timer);
return FALSE;
}
@ -534,7 +556,13 @@ gst_registry_xml_read_cache (GstRegistry * registry, const char *location)
GST_INFO ("loaded %s in %f seconds", location, seconds);
fclose (file);
#if GLIB_CHECK_VERSION(2,8,0)
if (mapped)
g_mapped_file_free (mapped);
#endif
if (file)
fclose (file);
return TRUE;
}