nautilus r13642 - in trunk: . libnautilus-extension libnautilus-private src/file-manager



Author: alexl
Date: Tue Jan 22 22:41:46 2008
New Revision: 13642
URL: http://svn.gnome.org/viewvc/nautilus?rev=13642&view=rev

Log:
2008-01-22  Alexander Larsson  <alexl redhat com>

        * libnautilus-extension/nautilus-column.c:
	Add attribute_q property that is the Quark
	of the attribute property.
	
        * src/file-manager/fm-icon-container.c:
        * src/file-manager/fm-list-model.[ch]:
        * src/file-manager/fm-list-view.c:
	Use the quark versions of the string attribute
	calls for better performance.



Modified:
   trunk/ChangeLog
   trunk/libnautilus-extension/nautilus-column.c
   trunk/libnautilus-private/nautilus-file.c
   trunk/src/file-manager/fm-icon-container.c
   trunk/src/file-manager/fm-list-model.c
   trunk/src/file-manager/fm-list-model.h
   trunk/src/file-manager/fm-list-view.c

Modified: trunk/libnautilus-extension/nautilus-column.c
==============================================================================
--- trunk/libnautilus-extension/nautilus-column.c	(original)
+++ trunk/libnautilus-extension/nautilus-column.c	Tue Jan 22 22:41:46 2008
@@ -30,6 +30,7 @@
 	PROP_0,
 	PROP_NAME,
 	PROP_ATTRIBUTE,
+	PROP_ATTRIBUTE_Q,
 	PROP_LABEL,
 	PROP_DESCRIPTION,
 	PROP_XALIGN,
@@ -38,7 +39,7 @@
 
 struct _NautilusColumnDetails {
 	char *name;
-	char *attribute;
+	GQuark attribute;
 	char *label;
 	char *description;
 	float xalign;
@@ -84,7 +85,10 @@
 		g_value_set_string (value, column->details->name);
 		break;
 	case PROP_ATTRIBUTE :
-		g_value_set_string (value, column->details->attribute);
+		g_value_set_string (value, g_quark_to_string (column->details->attribute));
+		break;
+	case PROP_ATTRIBUTE_Q :
+		g_value_set_uint (value, column->details->attribute);
 		break;
 	case PROP_LABEL :
 		g_value_set_string (value, column->details->label);
@@ -118,9 +122,9 @@
 		g_object_notify (object, "name");
 		break;
 	case PROP_ATTRIBUTE :
-		g_free (column->details->attribute);
-		column->details->attribute = g_strdup (g_value_get_string (value));
+		column->details->attribute = g_quark_from_string (g_value_get_string (value));
 		g_object_notify (object, "attribute");
+		g_object_notify (object, "attribute_q");
 		break;
 	case PROP_LABEL :
 		g_free (column->details->label);
@@ -150,7 +154,6 @@
 	column = NAUTILUS_COLUMN (object);
 
 	g_free (column->details->name);
-	g_free (column->details->attribute);
 	g_free (column->details->label);
 	g_free (column->details->description);
 
@@ -190,6 +193,13 @@
 							      NULL,
 							      G_PARAM_READWRITE));
 	g_object_class_install_property (G_OBJECT_CLASS (class),
+					 PROP_ATTRIBUTE_Q,
+					 g_param_spec_uint ("attribute_q",
+							    "Attribute quark",
+							    "The attribute name to display, in quark form",
+							    0, G_MAXUINT, 0,
+							    G_PARAM_READABLE));
+	g_object_class_install_property (G_OBJECT_CLASS (class),
 					 PROP_LABEL,
 					 g_param_spec_string ("label",
 							      "Label",

Modified: trunk/libnautilus-private/nautilus-file.c
==============================================================================
--- trunk/libnautilus-private/nautilus-file.c	(original)
+++ trunk/libnautilus-private/nautilus-file.c	Tue Jan 22 22:41:46 2008
@@ -5128,10 +5128,6 @@
 nautilus_file_get_string_attribute_q (NautilusFile *file, GQuark attribute_q)
 {
 	char *extension_attribute;
-	
-	/* FIXME bugzilla.gnome.org 40646: 
-	 * Use hash table and switch statement or function pointers for speed? 
-	 */
 
 	if (attribute_q == attribute_name_q) {
 		return nautilus_file_get_display_name (file);

Modified: trunk/src/file-manager/fm-icon-container.c
==============================================================================
--- trunk/src/file-manager/fm-icon-container.c	(original)
+++ trunk/src/file-manager/fm-icon-container.c	Tue Jan 22 22:41:46 2008
@@ -41,6 +41,8 @@
 			 NautilusIconContainer,
 			 nautilus_icon_container_get_type ())
 
+static GQuark attribute_none_q;
+
 static FMIconView *
 get_icon_view (NautilusIconContainer *container)
 {
@@ -176,20 +178,41 @@
 	}
 }
 
+static void
+update_captions (GQuark **attributes_p)
+{
+	char **attribute_names;
+	int i;
+
+	attribute_names = eel_preferences_get_string_array (NAUTILUS_PREFERENCES_ICON_VIEW_CAPTIONS);
+
+	g_free (*attributes_p);
+	*attributes_p = g_new (GQuark, g_strv_length (attribute_names) + 1);
+
+	for (i = 0; attribute_names[i] != NULL; ++i) {
+		(*attributes_p)[i] = g_quark_from_string (attribute_names[i]);
+	}
+	(*attributes_p)[i] = 0;
+	
+	g_strfreev (attribute_names);
+}
+
 /*
  * Get the preference for which caption text should appear
  * beneath icons.
  */
-static char **
+static GQuark *
 fm_icon_container_get_icon_text_attributes_from_preferences (void)
 {
-	static char **attributes;
+	static GQuark *attributes = NULL;
 
 	if (attributes == NULL) {
-		eel_preferences_add_auto_string_array (NAUTILUS_PREFERENCES_ICON_VIEW_CAPTIONS,
-						       &attributes);
+		eel_preferences_add_callback (NAUTILUS_PREFERENCES_ICON_VIEW_CAPTIONS,
+					      (EelPreferencesCallback)update_captions,
+					      &attributes);
+		update_captions (&attributes);
 	}
-
+	
 	/* We don't need to sanity check the attributes list even though it came
 	 * from preferences.
 	 *
@@ -219,6 +242,17 @@
 	return attributes;
 }
 
+static int
+quarkv_length (GQuark *attributes)
+{
+	int i;
+	i = 0;
+	while (attributes[i] != 0) {
+		i++;
+	}
+	return i;
+}
+
 /**
  * fm_icon_view_get_icon_text_attribute_names:
  *
@@ -228,11 +262,11 @@
  * @view: FMIconView to query.
  * 
  **/
-static char **
+static GQuark *
 fm_icon_container_get_icon_text_attribute_names (NautilusIconContainer *container,
 						 int *len)
 {
-	char **attributes;
+	GQuark *attributes;
 	int piece_count;
 
 	const int pieces_by_level[] = {
@@ -249,7 +283,7 @@
 
 	attributes = fm_icon_container_get_icon_text_attributes_from_preferences ();
 
-	*len = MIN (piece_count, g_strv_length (attributes));
+	*len = MIN (piece_count, quarkv_length (attributes));
 
 	return attributes;
 }
@@ -265,7 +299,7 @@
 {
 	char *actual_uri;
 	gchar *description;
-	char **attribute_names;
+	GQuark *attributes;
 	char *text_array[4];
 	int i, j, num_attributes;
 	FMIconView *icon_view;
@@ -312,27 +346,33 @@
 	}
 
 	/* Find out what attributes go below each icon. */
-	attribute_names = fm_icon_container_get_icon_text_attribute_names (container,
+	attributes = fm_icon_container_get_icon_text_attribute_names (container,
 									   &num_attributes);
 
 	/* Get the attributes. */
 	j = 0;
-	for (i = 0; i < num_attributes; ++i)
-	{
-		if (strcmp (attribute_names[i], "none") == 0) {
+	for (i = 0; i < num_attributes; ++i) {
+		if (attributes[i] == attribute_none_q) {
 			continue;
 		}
 
 		text_array[j++] =
-			nautilus_file_get_string_attribute_with_default (file, attribute_names[i]);
+			nautilus_file_get_string_attribute_with_default_q (file, attributes[i]);
 	}
 	text_array[j] = NULL;
 
 	/* Return them. */
-	*additional_text = g_strjoinv ("\n", text_array);
-
-	for (i = 0; i < j; i++) {
-		g_free (text_array[i]);
+	if (j == 0) {
+		*additional_text = NULL;
+	} else if (j == 1) {
+		/* Only one item, avoid the strdup + free */
+		*additional_text = text_array[0];
+	} else {
+		*additional_text = g_strjoinv ("\n", text_array);
+		
+		for (i = 0; i < j; i++) {
+			g_free (text_array[i]);
+		}
 	}
 }
 
@@ -494,6 +534,8 @@
 
 	ic_class = &klass->parent_class;
 
+	attribute_none_q = g_quark_from_static_string ("none");
+	
 	ic_class->get_icon_text = fm_icon_container_get_icon_text;
 	ic_class->get_icon_images = fm_icon_container_get_icon_images;
 	ic_class->get_icon_description = fm_icon_container_get_icon_description;

Modified: trunk/src/file-manager/fm-list-model.c
==============================================================================
--- trunk/src/file-manager/fm-list-model.c	(original)
+++ trunk/src/file-manager/fm-list-model.c	Tue Jan 22 22:41:46 2008
@@ -48,14 +48,18 @@
 	LAST_SIGNAL
 };
 
+static GQuark attribute_name_q,
+	attribute_modification_date_q,
+	attribute_date_modified_q;
+
 /* msec delay after Loading... dummy row turns into (empty) */
 #define LOADING_TO_EMPTY_DELAY 100
 
 static guint list_model_signals[LAST_SIGNAL] = { 0 };
 
 static int fm_list_model_file_entry_compare_func (gconstpointer a,
-				       gconstpointer b,
-				       gpointer      user_data);
+						  gconstpointer b,
+						  gpointer      user_data);
 
 static GObjectClass *parent_class;
 
@@ -66,7 +70,7 @@
 
 	int stamp;
 
-	char *sort_attribute;
+	GQuark sort_attribute;
 	GtkSortType order;
 
 	gboolean sort_directories_first;
@@ -363,25 +367,24 @@
  	default:
  		if (column >= FM_LIST_MODEL_NUM_COLUMNS || column < FM_LIST_MODEL_NUM_COLUMNS + model->details->columns->len) {
 			NautilusColumn *nautilus_column;
-			char *attribute;
+			GQuark attribute;
 			nautilus_column = model->details->columns->pdata[column - FM_LIST_MODEL_NUM_COLUMNS];
 			
 			g_value_init (value, G_TYPE_STRING);
 			g_object_get (nautilus_column, 
-				      "attribute", &attribute, 
+				      "attribute_q", &attribute, 
 				      NULL);
 			if (file != NULL) {
-				str = nautilus_file_get_string_attribute_with_default (file, 
-									       attribute);
+				str = nautilus_file_get_string_attribute_with_default_q (file, 
+											 attribute);
 				g_value_set_string_take_ownership (value, str);
-			} else if (!strcmp (attribute, "name")) {
+			} else if (attribute == attribute_name_q) {
 				if (file_entry->parent->loaded) {
 					g_value_set_string (value, _("(Empty)"));
 				} else {
 					g_value_set_string (value, _("Loading..."));
 				}
 			}
-			g_free (attribute);
 		} else {
 			g_assert_not_reached ();
 		}
@@ -642,10 +645,10 @@
 	file_entry2 = (FileEntry *)b;
 	
 	if (file_entry1->file != NULL && file_entry2->file != NULL) {
-		result = nautilus_file_compare_for_sort_by_attribute (file_entry1->file, file_entry2->file,
-							      model->details->sort_attribute,
-							      model->details->sort_directories_first,
-							      (model->details->order == GTK_SORT_DESCENDING));
+		result = nautilus_file_compare_for_sort_by_attribute_q (file_entry1->file, file_entry2->file,
+									model->details->sort_attribute,
+									model->details->sort_directories_first,
+									(model->details->order == GTK_SORT_DESCENDING));
 	} else if (file_entry1->file == NULL) {
 		return -1;
 	} else {
@@ -662,10 +665,10 @@
 {
 	int result;
 
-	result = nautilus_file_compare_for_sort_by_attribute (file1, file2,
-							      model->details->sort_attribute,
-							      model->details->sort_directories_first,
-							      (model->details->order == GTK_SORT_DESCENDING));
+	result = nautilus_file_compare_for_sort_by_attribute_q (file1, file2,
+								model->details->sort_attribute,
+								model->details->sort_directories_first,
+								(model->details->order == GTK_SORT_DESCENDING));
 
 	return result;
 }
@@ -778,7 +781,6 @@
 
 	model = (FMListModel *)sortable;
 
-	g_free (model->details->sort_attribute);
 	model->details->sort_attribute = fm_list_model_get_attribute_from_sort_column_id (model, sort_column_id);
 
 	model->details->order = order;
@@ -1309,57 +1311,55 @@
 
 int
 fm_list_model_get_sort_column_id_from_attribute (FMListModel *model,
-						 const char *attribute)
+						 GQuark attribute)
 {
 	guint i;
 
-	if (attribute == NULL) {
+	if (attribute == 0) {
 		return -1;
 	}
 
 	/* Hack - the preferences dialog sets modification_date for some 
 	 * rather than date_modified for some reason.  Make sure that 
 	 * works. */
-	if (!strcmp (attribute, "modification_date")) {
-		attribute = "date_modified";
+	if (attribute == attribute_modification_date_q) {
+		attribute = attribute_date_modified_q;
 	}
 
 	for (i = 0; i < model->details->columns->len; i++) {
 		NautilusColumn *column;
-		char *column_attribute;
+		GQuark column_attribute;
 		
 		column = 
 			NAUTILUS_COLUMN (model->details->columns->pdata[i]);
 		g_object_get (G_OBJECT (column), 
-			      "attribute", &column_attribute, 
+			      "attribute_q", &column_attribute, 
 			      NULL);
-		if (!strcmp (column_attribute, attribute)) {
-			g_free (column_attribute);
+		if (column_attribute == attribute) {
 			return FM_LIST_MODEL_NUM_COLUMNS + i;
 		}
-		g_free (column_attribute);
 	}
 	
 	return -1;
 }
 
-char *
+GQuark
 fm_list_model_get_attribute_from_sort_column_id (FMListModel *model,
 						 int sort_column_id)
 {
 	NautilusColumn *column;
 	int index;
-	char *attribute;
+	GQuark attribute;
 	
 	index = sort_column_id - FM_LIST_MODEL_NUM_COLUMNS;
 
 	if (index < 0 || index >= model->details->columns->len) {
 		g_warning ("unknown sort column id: %d", sort_column_id);
-		return NULL;
+		return 0;
 	}
 
 	column = NAUTILUS_COLUMN (model->details->columns->pdata[index]);
-	g_object_get (G_OBJECT (column), "attribute", &attribute, NULL);
+	g_object_get (G_OBJECT (column), "attribute_q", &attribute, NULL);
 
 	return attribute;
 }
@@ -1553,7 +1553,6 @@
 
 	model = FM_LIST_MODEL (object);
 
-	g_free (model->details->sort_attribute);
 	g_free (model->details);
 	
 	EEL_CALL_PARENT (G_OBJECT_CLASS, finalize, (object));
@@ -1567,7 +1566,7 @@
 	model->details->top_reverse_map = g_hash_table_new (g_direct_hash, g_direct_equal);
 	model->details->directory_reverse_map = g_hash_table_new (g_direct_hash, g_direct_equal);
 	model->details->stamp = g_random_int ();
-	model->details->sort_attribute = NULL;
+	model->details->sort_attribute = 0;
 	model->details->columns = g_ptr_array_new ();
 }
 
@@ -1576,6 +1575,10 @@
 {
 	GObjectClass *object_class;
 
+	attribute_name_q = g_quark_from_static_string ("name");
+	attribute_modification_date_q = g_quark_from_static_string ("modification_date");
+	attribute_date_modified_q = g_quark_from_static_string ("date_modified");
+	
 	object_class = (GObjectClass *)klass;
 	parent_class = g_type_class_peek_parent (klass);
 

Modified: trunk/src/file-manager/fm-list-model.h
==============================================================================
--- trunk/src/file-manager/fm-list-model.h	(original)
+++ trunk/src/file-manager/fm-list-model.h	Tue Jan 22 22:41:46 2008
@@ -99,9 +99,8 @@
 							  gboolean              sort_directories_first);
 
 int      fm_list_model_get_sort_column_id_from_attribute (FMListModel *model,
-
-							  const char           *attribute);
-char    *fm_list_model_get_attribute_from_sort_column_id (FMListModel *model,
+							  GQuark       attribute);
+GQuark   fm_list_model_get_attribute_from_sort_column_id (FMListModel *model,
 							  int sort_column_id);
 void     fm_list_model_sort_files                        (FMListModel *model,
 							  GList **files);

Modified: trunk/src/file-manager/fm-list-view.c
==============================================================================
--- trunk/src/file-manager/fm-list-view.c	(original)
+++ trunk/src/file-manager/fm-list-view.c	Tue Jan 22 22:41:46 2008
@@ -1005,7 +1005,7 @@
 	NautilusFile *file;
 	gint sort_column_id;
 	GtkSortType reversed;
-	char *sort_attr, *default_sort_attr;
+	GQuark sort_attr, default_sort_attr;
 	char *reversed_attr, *default_reversed_attr;
 
 	file = fm_directory_view_get_directory_as_file (FM_DIRECTORY_VIEW (view));
@@ -1013,12 +1013,11 @@
 	gtk_tree_sortable_get_sort_column_id (sortable, &sort_column_id, &reversed);
 
 	sort_attr = fm_list_model_get_attribute_from_sort_column_id (view->details->model, sort_column_id);
-	sort_column_id = fm_list_model_get_sort_column_id_from_attribute (view->details->model, default_sort_order_auto_value);
+	sort_column_id = fm_list_model_get_sort_column_id_from_attribute (view->details->model,
+									  g_quark_from_string (default_sort_order_auto_value));
 	default_sort_attr = fm_list_model_get_attribute_from_sort_column_id (view->details->model, sort_column_id);
 	nautilus_file_set_metadata (file, NAUTILUS_METADATA_KEY_LIST_VIEW_SORT_COLUMN,
-				    default_sort_attr, sort_attr);
-	g_free (default_sort_attr);
-	g_free (sort_attr);
+				    g_quark_to_string (default_sort_attr), g_quark_to_string (sort_attr));
 
 	default_reversed_attr = (default_sort_reversed_auto_value ? "true" : "false");
 	reversed_attr = (reversed ? "true" : "false");
@@ -1555,10 +1554,13 @@
 	sort_attribute = nautilus_file_get_metadata (file,
 						     NAUTILUS_METADATA_KEY_LIST_VIEW_SORT_COLUMN,
 						     NULL);
-	sort_column_id = fm_list_model_get_sort_column_id_from_attribute (list_view->details->model, sort_attribute);
+	sort_column_id = fm_list_model_get_sort_column_id_from_attribute (list_view->details->model,
+									  g_quark_from_string (sort_attribute));
 	g_free (sort_attribute);
 	if (sort_column_id == -1) {
-		sort_column_id = fm_list_model_get_sort_column_id_from_attribute (list_view->details->model, default_sort_order_auto_value);
+		sort_column_id =
+			fm_list_model_get_sort_column_id_from_attribute (list_view->details->model,
+									 g_quark_from_string (default_sort_order_auto_value));
 	}
 
 	sort_reversed = nautilus_file_get_boolean_metadata (file,
@@ -2156,7 +2158,8 @@
 
 	gtk_tree_sortable_set_sort_column_id
 		(GTK_TREE_SORTABLE (FM_LIST_VIEW (view)->details->model),
-		 fm_list_model_get_sort_column_id_from_attribute (FM_LIST_VIEW (view)->details->model, default_sort_order_auto_value),
+		 fm_list_model_get_sort_column_id_from_attribute (FM_LIST_VIEW (view)->details->model,
+								  g_quark_from_string (default_sort_order_auto_value)),
 		 default_sort_reversed_auto_value ? GTK_SORT_DESCENDING : GTK_SORT_ASCENDING);
 
 	fm_list_view_set_zoom_level (FM_LIST_VIEW (view), get_default_zoom_level (), FALSE);



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