[frogr] Speed up picture loading by tweaking how tags are imported from XMP data
- From: Mario Sanchez Prada <msanchez src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [frogr] Speed up picture loading by tweaking how tags are imported from XMP data
- Date: Sun, 7 Sep 2014 00:03:08 +0000 (UTC)
commit 7208fdfb106ede7c7982230bf0d1784e454e6c1d
Author: Mario Sanchez Prada <msanchez gnome org>
Date: Sun Sep 7 00:16:06 2014 +0100
Speed up picture loading by tweaking how tags are imported from XMP data
No need to copy memory around or use expensive functions to look for
those tags. This patch makes the process of importing tags much faster,
which in the tests I did locally resulted in an overall speed up of 300%
when loading 200 pictures of 5MB each.
https://bugzilla.gnome.org/show_bug.cgi?id=734202
src/frogr-file-loader.c | 73 ++++++++++++++++++++++++-----------------------
1 files changed, 37 insertions(+), 36 deletions(-)
---
diff --git a/src/frogr-file-loader.c b/src/frogr-file-loader.c
index 8241faa..50e80e6 100644
--- a/src/frogr-file-loader.c
+++ b/src/frogr-file-loader.c
@@ -688,9 +688,11 @@ remove_spaces_from_keyword (const gchar *keyword)
static gchar *
import_tags_from_xmp_keywords (const char *buffer, size_t len)
{
- gchar *comparison_substr = NULL;
- gchar *keywords_start = NULL;
- gchar *keywords_end = NULL;
+ const gchar *keywords_start = NULL;
+ const gchar *keywords_end = NULL;
+ gchar *keywords_string = NULL;
+ gchar *start = NULL;
+ gchar *end = NULL;
gchar *result = NULL;
int i;
@@ -698,50 +700,49 @@ import_tags_from_xmp_keywords (const char *buffer, size_t len)
present, that is, the keywords (aka the 'tags') */
for (i = 0; i < len && !keywords_start; i++)
{
- comparison_substr = g_strndup (&buffer[i], 11);
- if (g_str_has_prefix (comparison_substr, "<dc:subject"))
- keywords_start = g_strdup(&buffer[i]);
- g_free (comparison_substr);
+ if (buffer[i] != '<')
+ continue;
+
+ if (!strncmp (&buffer[i], "<dc:subject", 11))
+ keywords_start = &buffer[i];
}
/* Find the end of the interesting XMP data, if found */
- if (keywords_start)
- keywords_end = g_strrstr (keywords_start, "</dc:subject>");
+ if (!keywords_start)
+ return NULL;
- if (keywords_end)
- {
- gchar *start = NULL;
- gchar *end = NULL;
+ keywords_end = g_strrstr (keywords_start, "</dc:subject>");
+ if (!keywords_end)
+ return NULL;
- keywords_end[0] = '\0';
+ keywords_string = g_strndup (keywords_start, keywords_end - keywords_start);
- /* Remove extra not-needed stuff in the string */
- start = g_strstr_len (keywords_start, -1, "<rdf:li");
- end = g_strrstr (keywords_start, "</rdf:li>");
- if (start && end)
- {
- gchar **keywords = NULL;
- gchar *keyword = NULL;
+ /* Remove extra not-needed stuff in the string */
+ start = g_strstr_len (keywords_string, -1, "<rdf:li");
+ end = g_strrstr (keywords_string, "</rdf:li>");
+ if (start && end)
+ {
+ gchar **keywords = NULL;
+ gchar *keyword = NULL;
- /* Get an array of strings with all the keywords */
- end[0] = '\0';
- keywords = g_regex_split_simple ("<.?rdf:li(!>)*>", start,
- G_REGEX_DOTALL | G_REGEX_RAW, 0);
+ /* Get an array of strings with all the keywords */
+ end[0] = '\0';
+ keywords = g_regex_split_simple ("<.?rdf:li(!>)*>", start,
+ G_REGEX_DOTALL | G_REGEX_RAW, 0);
- /* Remove spaces to normalize to flickr tags */
- for (i = 0; keywords[i]; i++)
- {
- keyword = keywords[i];
- keywords[i] = remove_spaces_from_keyword (keyword);
- g_free (keyword);
- }
-
- result = g_strjoinv (" ", keywords);
- g_strfreev (keywords);
+ /* Remove spaces to normalize to flickr tags */
+ for (i = 0; keywords[i]; i++)
+ {
+ keyword = keywords[i];
+ keywords[i] = remove_spaces_from_keyword (keyword);
+ g_free (keyword);
}
+
+ result = g_strjoinv (" ", keywords);
+ g_strfreev (keywords);
}
- g_free (keywords_start);
+ g_free (keywords_string);
return result;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]