[gthumb] Reduce usage of strcmp to compare URIs and paths
- From: Michael J. Chudobiak <mjc src gnome org>
- To: svn-commits-list gnome org
- Subject: [gthumb] Reduce usage of strcmp to compare URIs and paths
- Date: Wed, 3 Jun 2009 20:07:11 -0400 (EDT)
commit 092f4772096c3178c727789e2a76f9feac78a61c
Author: Michael J. Chudobiak <mjc avtechpulse com>
Date: Wed Jun 3 20:06:29 2009 -0400
Reduce usage of strcmp to compare URIs and paths
Use improved uricmp and same_uri instead.
---
libgthumb/file-data.c | 8 ++++-
libgthumb/file-utils.c | 70 +++++++++++++++++++++++++++------------------
libgthumb/gth-monitor.c | 2 +-
libgthumb/pixbuf-utils.c | 2 +-
src/gth-browser.c | 4 +-
src/main.c | 12 ++++----
6 files changed, 59 insertions(+), 39 deletions(-)
diff --git a/libgthumb/file-data.c b/libgthumb/file-data.c
index e145a42..4fbfcf4 100644
--- a/libgthumb/file-data.c
+++ b/libgthumb/file-data.c
@@ -339,14 +339,20 @@ file_data_list_find_path (GList *list,
const char *path)
{
GList *scan;
+ char *utf8_path;
+
+ utf8_path = get_utf8_display_name_from_uri (path);
for (scan = list; scan; scan = scan->next) {
FileData *data = scan->data;
- if (strcmp (data->utf8_path, path) == 0)
+ if (strcmp (data->utf8_path, utf8_path) == 0) {
+ g_free (utf8_path);
return scan;
+ }
}
+ g_free (utf8_path);
return NULL;
}
diff --git a/libgthumb/file-utils.c b/libgthumb/file-utils.c
index 4a40352..660a802 100644
--- a/libgthumb/file-utils.c
+++ b/libgthumb/file-utils.c
@@ -1264,25 +1264,31 @@ int
uricmp (const char *path1,
const char *path2)
{
- char *uri1, *uri2;
- char *key1, *key2;
int result;
- uri1 = get_utf8_display_name_from_uri (path1);
- uri2 = get_utf8_display_name_from_uri (path2);
- key1 = g_utf8_collate_key_for_filename (uri1, -1);
- key2 = g_utf8_collate_key_for_filename (uri2, -1);
+ /* handle catalog:// uris specially */
+ if ((path1 == NULL) || (path2 == NULL) ||
+ uri_scheme_is_catalog (path1) || uri_scheme_is_catalog (path2)) {
+ result = strcmp_null_tolerant (path1, path2);
+ } else {
+ char *uri1, *uri2;
+ char *key1, *key2;
- result = strcmp_null_tolerant (key1, key2);
+ uri1 = get_utf8_display_name_from_uri (path1);
+ uri2 = get_utf8_display_name_from_uri (path2);
+ key1 = g_utf8_collate_key_for_filename (uri1, -1);
+ key2 = g_utf8_collate_key_for_filename (uri2, -1);
- g_free (uri1);
- g_free (uri2);
- g_free (key1);
- g_free (key2);
+ result = strcmp_null_tolerant (key1, key2);
- return result;
+ g_free (uri1);
+ g_free (uri2);
+ g_free (key1);
+ g_free (key2);
+ }
+ return result;
}
@@ -1290,24 +1296,32 @@ gboolean
same_uri (const char *uri1,
const char *uri2)
{
- GFile *gfile1;
- GFile *gfile2;
gboolean result = FALSE;
- /* quick test */
- if (strcmp_null_tolerant (uri1, uri2) == 0)
- return TRUE;
- if ((uri1 == NULL) || (uri2 == NULL))
- return FALSE;
+ /* catalog:// isn't handled by gfile, of course */
+ if ((uri1 == NULL) || (uri2 == NULL) ||
+ uri_scheme_is_catalog (uri1) || uri_scheme_is_catalog (uri2)) {
+ result = !strcmp_null_tolerant (uri1, uri2);
+ } else {
+ /* quick test */
+ if (strcmp_null_tolerant (uri1, uri2) == 0) {
+ result = TRUE;
+ } else if ((uri1 == NULL) || (uri2 == NULL)) {
+ result = FALSE;
+ } else {
+ /* slow test */
+ GFile *gfile1;
+ GFile *gfile2;
- /* slow test */
- gfile1 = gfile_new (uri1);
- gfile2 = gfile_new (uri2);
+ gfile1 = gfile_new (uri1);
+ gfile2 = gfile_new (uri2);
- result = g_file_equal (gfile1, gfile2);
+ result = g_file_equal (gfile1, gfile2);
- g_object_unref (gfile1);
- g_object_unref (gfile2);
+ g_object_unref (gfile1);
+ g_object_unref (gfile2);
+ }
+ }
return result;
}
diff --git a/libgthumb/gth-monitor.c b/libgthumb/gth-monitor.c
index c780207..5f9602b 100644
--- a/libgthumb/gth-monitor.c
+++ b/libgthumb/gth-monitor.c
@@ -126,7 +126,7 @@ find_monitor_from_uri (GList *gfile_monitors,
for (scan = gfile_monitors; scan; scan = scan->next) {
MonitorHandle *mh = scan->data;
- if (strcmp (mh->uri, utf8_uri) == 0)
+ if (same_uri (mh->uri, utf8_uri))
return scan;
}
diff --git a/libgthumb/pixbuf-utils.c b/libgthumb/pixbuf-utils.c
index 6470482..2dc3f4c 100644
--- a/libgthumb/pixbuf-utils.c
+++ b/libgthumb/pixbuf-utils.c
@@ -1207,7 +1207,7 @@ _gdk_pixbuf_savev (GdkPixbuf *pixbuf,
/* Make a backup copy of original file if the source and destination
* are the same, so that we can copy the metadata. */
if (original_local_file != NULL) {
- if (!strcmp (local_file, original_local_file)) {
+ if (same_uri (local_file, original_local_file)) {
temp_dir = get_temp_dir_name ();
if (temp_dir != NULL) {
char *ext;
diff --git a/src/gth-browser.c b/src/gth-browser.c
index ef32005..6ecfb06 100644
--- a/src/gth-browser.c
+++ b/src/gth-browser.c
@@ -4336,7 +4336,7 @@ activate_catalog_done (GthBrowser *browser)
if ((priv->go_op == GTH_BROWSER_GO_TO)
&& ((priv->history_current == NULL)
|| ((priv->catalog_path != NULL)
- && (strcmp (priv->catalog_path, remove_host_from_uri (priv->history_current->data)) != 0)))) {
+ && (!same_uri (priv->catalog_path, remove_host_from_uri (priv->history_current->data)))))) {
GtkTreeIter iter;
gboolean is_search;
@@ -7735,7 +7735,7 @@ gth_browser_show_catalog_directory (GthBrowser *browser,
if ((catalog_dir == NULL)
|| (strlen (catalog_dir) == 0)
- || (strcmp (catalog_dir, "file:///") == 0))
+ || (same_uri (catalog_dir, "file:///")))
{
catalog_dir2 = g_strconcat (get_home_uri (),
"/",
diff --git a/src/main.c b/src/main.c
index a59b1ab..d81078e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -399,7 +399,7 @@ reset_command_line_catalog (void)
catalog_path = get_command_line_catalog_path ();
catalog_uri = g_strconcat ("catalog://", remove_host_from_uri (catalog_path), NULL);
- if (strcmp (catalog_uri, preferences_get_startup_location ()) == 0)
+ if (same_uri (catalog_uri, preferences_get_startup_location ()))
preferences_set_startup_location (get_home_uri ());
g_free (catalog_uri);
@@ -836,9 +836,9 @@ get_stock_id_for_uri (const char *uri)
{
const char *stock_id;
- if (strcmp (uri, g_get_home_dir ()) == 0)
+ if (same_uri (uri, g_get_home_dir ()))
stock_id = GTK_STOCK_HOME;
- else if (strcmp (uri, get_home_uri ()) == 0)
+ else if (same_uri (uri, get_home_uri ()))
stock_id = GTK_STOCK_HOME;
else if (uri_scheme_is_catalog (uri))
stock_id = GTHUMB_STOCK_CATALOG;
@@ -860,12 +860,12 @@ get_icon_for_uri (GtkWidget *widget,
menu_size = get_folder_pixbuf_size_for_list (widget);
- if (strcmp (uri, g_get_home_dir ()) == 0)
+ if (same_uri (uri, g_get_home_dir ()))
return get_fs_icon (ICON_NAME_HOME, menu_size);
- else if (strcmp (uri, get_home_uri ()) == 0)
+ else if (same_uri (uri, get_home_uri ()))
return get_fs_icon (ICON_NAME_HOME, menu_size);
- if ((strcmp (uri, "file:///") == 0) || (strcmp (uri, "/") == 0))
+ if (same_uri (uri, "file:///"))
return get_fs_icon (ICON_NAME_HARDDISK, menu_size);
if (uri_scheme_is_catalog (uri)) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]