Merge lp:~rodrigo-moya/ubuntuone-client/use-hash-tables into lp:ubuntuone-client

Proposed by Rodrigo Moya
Status: Merged
Approved by: Nicola Larosa
Approved revision: 59
Merged at revision: not available
Proposed branch: lp:~rodrigo-moya/ubuntuone-client/use-hash-tables
Merge into: lp:ubuntuone-client
Diff against target: None lines
To merge this branch: bzr merge lp:~rodrigo-moya/ubuntuone-client/use-hash-tables
Reviewer Review Type Date Requested Status
Lucio Torre (community) Approve
dobey (community) Approve
Review via email: mp+7936@code.launchpad.net

Commit message

[r=dobey, r=lucio.torre] Use GHashTable instead of GSList for a slight performance win

To post a comment you must log in.
Revision history for this message
Rodrigo Moya (rodrigo-moya) wrote :

Searching in GSList's can become quite slow when the uploads/downloads/shares lists become big (think 'uploading my whole photo collection') since it needs to iterate over the whole list. Using hash tables should be quicker for small lists and much more quicker for big/huge ones

Revision history for this message
dobey (dobey) :
review: Approve
59. By Rodrigo Moya

Added instructions to test Nautilus extension with jhbuild

Revision history for this message
Lucio Torre (lucio.torre) wrote :

code looks great. couldn't test it.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nautilus/ubuntuone-nautilus.c'
2--- nautilus/ubuntuone-nautilus.c 2009-06-17 20:04:32 +0000
3+++ nautilus/ubuntuone-nautilus.c 2009-06-26 11:11:21 +0000
4@@ -61,9 +61,9 @@
5 GHashTable * buttons;
6
7 /* Lists of ul/dl/shares for setting emblems */
8- GSList * uploads;
9- GSList * downloads;
10- GSList * shares;
11+ GHashTable * uploads;
12+ GHashTable * downloads;
13+ GHashTable * shares;
14 } UbuntuOneNautilus;
15
16 typedef struct {
17@@ -147,13 +147,13 @@
18
19 path = g_filename_from_uri (nautilus_file_info_get_uri (file), NULL, NULL);
20
21- if (g_slist_find (uon->uploads, path))
22+ if (g_hash_table_lookup (uon->uploads, path))
23 nautilus_file_info_add_emblem (file, "ubuntuone-uploading");
24
25- if (g_slist_find (uon->downloads, path))
26+ if (g_hash_table_lookup (uon->downloads, path))
27 nautilus_file_info_add_emblem (file, "ubuntuone-downloading");
28
29- if (g_slist_find (uon->shares, path))
30+ if (g_hash_table_lookup (uon->shares, path))
31 nautilus_file_info_add_emblem (file, "shared");
32
33 return NAUTILUS_OPERATION_COMPLETE;
34@@ -476,9 +476,9 @@
35
36 static void ubuntuone_nautilus_instance_init (UbuntuOneNautilus * uon) {
37 uon->connected = FALSE;
38- uon->uploads = NULL;
39- uon->downloads = NULL;
40- uon->shares = NULL;
41+ uon->uploads = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
42+ uon->downloads = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
43+ uon->shares = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
44
45 /* Magic bag of holding +10:
46 * We store some button widgets in a hash table here, so that we can
47@@ -571,28 +571,13 @@
48 g_object_unref (uon->u1_status);
49 g_object_unref (uon->bus);
50
51- for (l = uon->uploads; l != NULL; l = l->next) {
52- char * file = l->data;
53- uon->uploads = g_slist_remove (uon->uploads, file);
54- g_free (file);
55- }
56- g_slist_free (uon->uploads);
57+ g_hash_table_destroy (uon->uploads);
58 uon->uploads = NULL;
59
60- for (l = uon->downloads; l != NULL; l = l->next) {
61- char * file = l->data;
62- uon->downloads = g_slist_remove (uon->downloads, file);
63- g_free (file);
64- }
65- g_slist_free (uon->downloads);
66+ g_hash_table_destroy (uon->downloads);
67 uon->downloads = NULL;
68
69- for (l = uon->shares; l != NULL; l = l->next) {
70- char * file = l->data;
71- uon->shares = g_slist_remove (uon->shares, file);
72- g_free (file);
73- }
74- g_slist_free (uon->shares);
75+ g_hash_table_destroy (uon->shares);
76 uon->shares = NULL;
77
78 g_hash_table_destroy (uon->buttons);
79@@ -780,8 +765,9 @@
80 gpointer user_data) {
81 UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS (user_data);
82
83- if (!g_slist_find (uon->uploads, path)) {
84- uon->uploads = g_slist_prepend (uon->uploads, path);
85+ if (!g_hash_table_lookup (uon->uploads, path)) {
86+ gchar *new_path = g_strdup (path);
87+ g_hash_table_insert (uon->uploads, new_path, new_path);
88 utime (path, NULL);
89 }
90 }
91@@ -791,7 +777,7 @@
92 gpointer user_data) {
93 UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS (user_data);
94
95- uon->uploads = g_slist_remove (uon->uploads, path);
96+ g_hash_table_remove (uon->uploads, path);
97 utime (path, NULL);
98 }
99
100@@ -809,8 +795,9 @@
101 else
102 usepath = partial;
103
104- if (!g_slist_find (uon->uploads, usepath)) {
105- uon->downloads = g_slist_prepend (uon->downloads, g_strdup (usepath));
106+ if (!g_hash_table_lookup (uon->uploads, usepath)) {
107+ gchar *new_path = g_strdup (usepath);
108+ g_hash_table_insert (uon->downloads, new_path, new_path);
109 if (!g_file_test (usepath, G_FILE_TEST_EXISTS)) {
110 fd = open (usepath, O_WRONLY | O_CREAT | O_NONBLOCK | O_NOCTTY,
111 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
112@@ -834,7 +821,7 @@
113 else
114 usepath = partial;
115
116- uon->downloads = g_slist_remove (uon->downloads, usepath);
117+ g_hash_table_remove (uon->downloads, usepath);
118 utime (usepath, NULL);
119
120 g_free (partial);
121@@ -847,8 +834,10 @@
122 gchar * path;
123
124 path = g_hash_table_lookup (hash, "path");
125- if (!g_slist_find (uon->shares, path))
126- uon->shares = g_slist_prepend (uon->shares, path);
127+ if (!g_hash_table_lookup (uon->shares, path)) {
128+ gchar *new_share = g_strdup (path);
129+ g_hash_table_insert (uon->shares, new_share, new_share);
130+ }
131 }
132
133 /* Required Nautilus module handling methods */

Subscribers

People subscribed via source and target branches