tracker r1107 - in trunk: . src/trackerd



Author: carlosg
Date: Tue Jan 29 10:55:12 2008
New Revision: 1107
URL: http://svn.gnome.org/viewvc/tracker?rev=1107&view=rev

Log:
2008-01-29  Carlos Garnacho  <carlos imendio com>

        * src/trackerd/tracker-db-sqlite.c (tracker_db_search_text): Avoid
        doing too many relocations of data in memory. Bug #511781.
        * src/trackerd/tracker-utils.c (array_to_list): Same here.


Modified:
   trunk/ChangeLog
   trunk/src/trackerd/tracker-db-sqlite.c
   trunk/src/trackerd/tracker-utils.c

Modified: trunk/src/trackerd/tracker-db-sqlite.c
==============================================================================
--- trunk/src/trackerd/tracker-db-sqlite.c	(original)
+++ trunk/src/trackerd/tracker-db-sqlite.c	Tue Jan 29 10:55:12 2008
@@ -3050,12 +3050,13 @@
 char ***
 tracker_db_search_text (DBConnection *db_con, const char *service, const char *search_string, int offset, int limit, gboolean save_results, gboolean detailed)
 {
-	char 		**result, **array;
+	char 		***result, **array;
 	GSList 		*hit_list;
 	int 		count;
 	const GSList	*tmp;
 	gboolean	detailed_emails = FALSE, detailed_apps = FALSE;
 	int		service_array[255];
+	const gchar     *procedure;
 
 	array = tracker_parse_text_into_array (search_string);
 
@@ -3106,7 +3107,7 @@
 
 		if (count > limit) count = limit;
 
-		result = g_new (char *, count + 1);
+		result = g_new (char **, count + 1);
 	} else {
 		tracker_db_start_transaction (db_con);
 		tracker_exec_proc (db_con, "DeleteSearchResults1", 0);
@@ -3141,23 +3142,20 @@
 		}
 
 		if (detailed) {
-
 			if (strcmp (service, "Emails") == 0) {
 				detailed_emails = TRUE;
-				res = tracker_exec_proc_ignore_nulls (db_con, "GetEmailByID", 1, str_id);
-
+				procedure = "GetEmailByID";
 			} else if (strcmp (service, "Applications") == 0) {
 				detailed_apps = TRUE;
-				res = tracker_exec_proc_ignore_nulls (db_con, "GetApplicationByID", 1, str_id);
-
+				procedure = "GetApplicationByID";
 			} else {
-				res = tracker_exec_proc_ignore_nulls (db_con, "GetFileByID2", 1, str_id);
+				procedure = "GetFileByID2";
 			}
-
 		} else {
-			res = tracker_exec_proc_ignore_nulls (db_con, "GetFileByID", 1, str_id);
+			procedure = "GetFileByID";
 		}
 
+		res = tracker_exec_proc_ignore_nulls (db_con, procedure, 1, str_id);
 		g_free (str_id);
 
 		if (res) {
@@ -3166,84 +3164,21 @@
 				char **row = NULL;
 
 				if (detailed) {
-
-					if (detailed_emails) {
-						row = g_new0 (char *, 6);
-
-						row[0] = g_strdup (res[0][0]);
-						row[1] = g_strdup (res[0][1]);
-						row[2] = NULL;
-						row[3] = NULL;
-						row[4] = NULL;
-						row[5] = NULL;
-
-						if (res[0][2]) {
-							row[2] = g_strdup (res[0][2]);						
-							if (res[0][3]) {
-								row[3] = g_strdup (res[0][3]);	
-								if (res[0][4]) {
-									row[4] = g_strdup (res[0][4]);						
-								}	
-							}
-							
-
-							 
-						}					
-						
-
-					} else if (detailed_apps) {
-						row = g_new0 (char *, 7);
-
-						row[0] = g_strdup (res[0][0]);
-						row[1] = g_strdup (res[0][1]);
-						row[2] = g_strdup (res[0][2]);
-						row[3] = NULL;
-						row[4] = NULL;
-						row[5] = NULL;
-						row[6] = NULL;
-
-						if (res[0][3]) {
-							row[3] = g_strdup (res[0][3]);							
-							if (res[0][4]) {
-								row[4] = g_strdup (res[0][4]);	
-								if (res[0][5]) {
-									row[5] = g_strdup (res[0][5]);						
-								}	
-							}
-							
-
-							 
-						}			
-
-
-					} else {
-
-						if (res[0][2] && g_file_test (res[0][0], G_FILE_TEST_EXISTS)) {
-
-							row = g_new (char *, 4);
-
-							row[0] = g_strdup (res[0][0]);
-							row[1] = g_strdup (res[0][1]);
-							row[2] = g_strdup (res[0][2]);
-							row[3] = NULL;
-						}
+					if (detailed_emails || detailed_apps)
+						row = res[0];
+					else {
+						if (res[0][2] && g_file_test (res[0][0], G_FILE_TEST_EXISTS))
+							row = res[0];
 					}
-
 				} else {
-
-					row = g_new (char *, 3);
-
-					row[0] = g_strdup (res[0][0]);
-					row[1] = g_strdup (res[0][1]);
-					row[2] = NULL;
+					row = res[0];
 				}
 				
-				result[count] = (char *) row;
+				result[count] = row;
 				count++;
 			}
 
-			tracker_db_free_result (res);
-
+			g_free (res);
 		} else {
 			tracker_log ("dud hit for search detected");
 			/* add to dud list */

Modified: trunk/src/trackerd/tracker-utils.c
==============================================================================
--- trunk/src/trackerd/tracker-utils.c	(original)
+++ trunk/src/trackerd/tracker-utils.c	Tue Jan 29 10:55:12 2008
@@ -817,7 +817,7 @@
 }
 
 
-gboolean
+inline gboolean
 tracker_is_empty_string (const char *s)
 {
 	return s == NULL || s[0] == '\0';
@@ -2169,18 +2169,16 @@
 static GSList *
 array_to_list (char **array)
 {
-	GSList  *list;
+	GSList  *list = NULL;
 	int	i;
 
-	list = NULL;
-
 	for (i = 0; array[i] != NULL; i++) {
                 if (!tracker_is_empty_string (array[i])) {
-			list = g_slist_prepend (list, g_strdup (array[i]));
+			list = g_slist_prepend (list, array[i]);
 		}
 	}
 
-	g_strfreev (array);
+	g_free (array);
 
 	return list;
 }



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