[gthumb] Speed up filename and FileData comparison routines



commit e8f96895c3883f8c585fe5e6e24c66cb43a24a31
Author: Michael J. Chudobiak <mjc avtechpulse com>
Date:   Tue Jun 2 09:04:56 2009 -0400

    Speed up filename and FileData comparison routines
---
 libgthumb/file-data.c  |   13 +++++++++----
 libgthumb/file-utils.c |   21 +++++++++++++--------
 2 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/libgthumb/file-data.c b/libgthumb/file-data.c
index 0aa336f..e145a42 100644
--- a/libgthumb/file-data.c
+++ b/libgthumb/file-data.c
@@ -355,18 +355,23 @@ gboolean
 file_data_same_path (FileData   *fd1,
 		     const char *path2)
 {
-	FileData *fd2;
+	char *utf8_path2;
 	gboolean result;
 
 	if ((fd1 == NULL) && (path2 == NULL))
 		return TRUE;
 	if ((fd1 == NULL) || (path2 == NULL))
 		return FALSE;
+	if ((fd1->utf8_path == NULL))
+		return FALSE;
+
+	utf8_path2 = get_utf8_display_name_from_uri (path2);
+	if (utf8_path2 == NULL)
+		return FALSE;
 
-	fd2 = file_data_new (path2);
-	result = !strcmp (fd1->utf8_path,fd2->utf8_path);
+	result = !strcmp (fd1->utf8_path,utf8_path2);
+	g_free (utf8_path2);    
 
-	file_data_unref (fd2);
 	return result;
 }
 
diff --git a/libgthumb/file-utils.c b/libgthumb/file-utils.c
index 8452655..dc348ee 100644
--- a/libgthumb/file-utils.c
+++ b/libgthumb/file-utils.c
@@ -1270,18 +1270,23 @@ gboolean
 same_uri (const char *uri1,
 	  const char *uri2)
 {
-	FileData *fd1;
-	FileData *fd2;
-	gboolean  result = FALSE;
+	char     *utf8_path1;
+	char     *utf8_path2;
+	gboolean  result = FALSE;	
 
-	fd1 = file_data_new (uri1);
-	fd2 = file_data_new (uri2);
+	/* quick test */
+	if (strcmp_null_tolerant (uri1, uri2) == 0)
+		return TRUE;
+
+	/* slow test */
+	utf8_path1 = get_utf8_display_name_from_uri (uri1);
+	utf8_path2 = get_utf8_display_name_from_uri (uri2);
 
-	if (strcmp (fd1->utf8_path, fd2->utf8_path) == 0)
+	if (strcmp_null_tolerant (utf8_path1, utf8_path2) == 0)
 		result = TRUE;
 
-	file_data_unref (fd1);
-	file_data_unref (fd2);
+	g_free (utf8_path1);
+	g_free (utf8_path2);
 
 	return result;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]