1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
From: Sebastien Bacher <seb128@ubuntu.com>
Date: Sun, 24 Nov 2013 05:43:13 +0800
Subject: Upstream change to speed up itdb_resolve_path calls
---
src/itdb_itunesdb.c | 79 ++++++-----------------------------------------------
1 file changed, 8 insertions(+), 71 deletions(-)
diff --git a/src/itdb_itunesdb.c b/src/itdb_itunesdb.c
index a177e26..59acdd4 100644
--- a/src/itdb_itunesdb.c
+++ b/src/itdb_itunesdb.c
@@ -420,81 +420,18 @@ static void itdb_fsync (void)
gchar * itdb_resolve_path (const gchar *root,
const gchar * const * components)
{
- gchar *good_path;
- guint32 i;
+ gchar *absolute_path;
+ gchar *rel_path;
if (!root) return NULL;
- good_path = g_strdup (root);
-
- for(i = 0 ; components[i] ; i++) {
- GDir *cur_dir;
- gchar *component_as_filename;
- gchar *test_path;
- gchar *component_stdcase;
- const gchar *dir_file=NULL;
-
- /* skip empty components */
- if (strlen (components[i]) == 0) continue;
- component_as_filename =
- g_filename_from_utf8(components[i],-1,NULL,NULL,NULL);
- test_path = g_build_filename(good_path,component_as_filename,NULL);
- g_free(component_as_filename);
- if(g_file_test(test_path,G_FILE_TEST_EXISTS)) {
- /* This component does not require fixup */
- g_free(good_path);
- good_path = test_path;
- continue;
- }
- g_free(test_path);
- component_stdcase = g_utf8_casefold(components[i],-1);
- /* Case insensitively compare the current component with each entry
- * in the current directory. */
-
- cur_dir = g_dir_open(good_path,0,NULL);
- if (cur_dir) while ((dir_file = g_dir_read_name(cur_dir)))
- {
- gchar *file_utf8;
- gchar *file_stdcase;
- gboolean found;
- gchar *new_good_path;
-
- file_utf8 = g_filename_to_utf8(dir_file,-1,NULL,NULL,NULL);
- if (file_utf8 == NULL) {
- continue;
- }
- file_stdcase = g_utf8_casefold(file_utf8,-1);
- g_free(file_utf8);
- found = !g_utf8_collate(file_stdcase,component_stdcase);
- g_free(file_stdcase);
- if(!found)
- {
- /* This is not the matching entry */
- continue;
- }
-
- new_good_path = g_build_filename(good_path,dir_file,NULL);
- g_free(good_path);
- good_path= new_good_path;
- /* This is the matching entry, so we can stop searching */
- break;
- }
-
- if(!dir_file) {
- /* We never found a matching entry */
- g_free(good_path);
- good_path = NULL;
- }
-
- g_free(component_stdcase);
- if (cur_dir) g_dir_close(cur_dir);
- if(!good_path || !g_file_test(good_path,G_FILE_TEST_EXISTS))
- break; /* We couldn't fix this component, so don't try later ones */
+ rel_path = g_build_filenamev ((gchar **)components);
+ absolute_path = g_build_filename (root, rel_path, NULL);
+ g_free (rel_path);
+ if (g_file_test (absolute_path, G_FILE_TEST_EXISTS)) {
+ return absolute_path;
}
-
- if(good_path && g_file_test(good_path,G_FILE_TEST_EXISTS))
- return good_path;
+ g_free (absolute_path);
- g_free (good_path);
return NULL;
}
|