Commit 0c5414e6 authored by Christian Persch's avatar Christian Persch Committed by Christian Persch

Remove some small allocations, and use GSlice more often. Bug #461795.

2007-12-03  Christian Persch  <chpe@gnome.org>

	* libnautilus-private/nautilus-directory-metafile.c:
	(nautilus_directory_get_integer_file_metadata),
	(nautilus_directory_set_integer_file_metadata):
	* libnautilus-private/nautilus-directory.c:
	(nautilus_directory_schedule_position_set):
	* libnautilus-private/nautilus-dnd.c: (add_one_gnome_icon):
	* libnautilus-private/nautilus-file-operations-progress.c:
	(time_remaining_callback):
	* libnautilus-private/nautilus-icon-dnd.c: (handle_local_move):
	* src/file-manager/fm-directory-view.c: (new_folder_done):
	* src/nautilus-application.c: (get_desktop_manager_selection):
	* src/nautilus-connect-server-dialog.c: (display_server_uri):
	* src/nautilus-information-panel.c: (receive_dropped_color):
	* src/nautilus-property-browser.c: (add_color_to_browser):
	* src/nautilus-window.c: (nautilus_window_init),
	(nautilus_window_finalize), (free_activate_view_data),
	(add_view_as_menu_item), (nautilus_window_synch_view_as_menus),
	(nautilus_window_class_init): Remove some small allocations, and use
	GSlice more often. Bug #461795.

svn path=/trunk/; revision=13479
parent a35f1589
2007-12-03 Christian Persch <chpe@gnome.org>
* libnautilus-private/nautilus-directory-metafile.c:
(nautilus_directory_get_integer_file_metadata),
(nautilus_directory_set_integer_file_metadata):
* libnautilus-private/nautilus-directory.c:
(nautilus_directory_schedule_position_set):
* libnautilus-private/nautilus-dnd.c: (add_one_gnome_icon):
* libnautilus-private/nautilus-file-operations-progress.c:
(time_remaining_callback):
* libnautilus-private/nautilus-icon-dnd.c: (handle_local_move):
* src/file-manager/fm-directory-view.c: (new_folder_done):
* src/nautilus-application.c: (get_desktop_manager_selection):
* src/nautilus-connect-server-dialog.c: (display_server_uri):
* src/nautilus-information-panel.c: (receive_dropped_color):
* src/nautilus-property-browser.c: (add_color_to_browser):
* src/nautilus-window.c: (nautilus_window_init),
(nautilus_window_finalize), (free_activate_view_data),
(add_view_as_menu_item), (nautilus_window_synch_view_as_menus),
(nautilus_window_class_init): Remove some small allocations, and use
GSlice more often. Bug #461795.
2007-12-03 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/nautilus-file-operations.c:
......
......@@ -429,11 +429,11 @@ nautilus_directory_get_integer_file_metadata (NautilusDirectory *directory,
int default_metadata)
{
char *result_as_string;
char *default_as_string;
char default_as_string[32];
int result;
char c;
default_as_string = g_strdup_printf ("%d", default_metadata);
g_snprintf (default_as_string, sizeof (default_as_string), "%d", default_metadata);
result_as_string = nautilus_directory_get_file_metadata
(directory, file_name, key, default_as_string);
......@@ -449,7 +449,6 @@ nautilus_directory_get_integer_file_metadata (NautilusDirectory *directory,
g_free (result_as_string);
}
g_free (default_as_string);
return result;
}
......@@ -460,18 +459,15 @@ nautilus_directory_set_integer_file_metadata (NautilusDirectory *directory,
int default_metadata,
int metadata)
{
char *value_as_string;
char *default_as_string;
char value_as_string[32];
char default_as_string[32];
value_as_string = g_strdup_printf ("%d", metadata);
default_as_string = g_strdup_printf ("%d", default_metadata);
g_snprintf (value_as_string, sizeof (value_as_string), "%d", metadata);
g_snprintf (default_as_string, sizeof (default_as_string), "%d", default_metadata);
nautilus_directory_set_file_metadata
(directory, file_name, key,
default_as_string, value_as_string);
g_free (value_as_string);
g_free (default_as_string);
}
void
......
......@@ -1593,8 +1593,7 @@ nautilus_directory_schedule_position_set (GList *position_setting_list)
GList *p;
const NautilusFileChangesQueuePosition *item;
NautilusFile *file;
char *position_string;
char *screen_string;
char str[64];
for (p = position_setting_list; p != NULL; p = p->next) {
item = (NautilusFileChangesQueuePosition *) p->data;
......@@ -1602,29 +1601,26 @@ nautilus_directory_schedule_position_set (GList *position_setting_list)
file = nautilus_file_get (item->location);
if (item->set) {
position_string = g_strdup_printf ("%d,%d",
item->point.x, item->point.y);
g_snprintf (str, sizeof (str), "%d,%d", item->point.x, item->point.y);
} else {
position_string = NULL;
str[0] = 0;
}
nautilus_file_set_metadata
(file,
NAUTILUS_METADATA_KEY_ICON_POSITION,
NULL,
position_string);
g_free (position_string);
str);
if (item->set) {
screen_string = g_strdup_printf ("%d", item->screen);
g_snprintf (str, sizeof (str), "%d", item->screen);
} else {
screen_string = NULL;
str[0] = 0;
}
nautilus_file_set_metadata
(file,
NAUTILUS_METADATA_KEY_SCREEN,
NULL,
screen_string);
g_free (screen_string);
str);
nautilus_file_unref (file);
}
......
......@@ -427,13 +427,11 @@ add_one_gnome_icon (const char *uri, int x, int y, int w, int h,
gpointer data)
{
GString *result;
char *s;
result = (GString *) data;
s = g_strdup_printf ("%s\r%d:%d:%hu:%hu\r\n",
uri, x, y, w, h);
g_string_append (result, s);
g_free (s);
g_string_append_printf (result, "%s\r%d:%d:%hu:%hu\r\n",
uri, x, y, w, h);
}
/*
......
......@@ -441,7 +441,7 @@ time_remaining_callback (gpointer callback_data)
/* This shouldn't be neccessary, but gnome-vfs seems to add the bytes processed during
* the cleanup phase to bytes_copied. So we try avoid showing unrealistic ETAs here.
*/
str = g_strdup_printf ("%s", " ");
str = g_strdup (" ");
}
else if (time_remaining >= 3600) {
str = g_strdup_printf (_("(%d:%02d:%02d Remaining)"),
......
......@@ -928,7 +928,7 @@ handle_local_move (NautilusIconContainer *container,
NautilusDragSelectionItem *item;
NautilusIcon *icon;
NautilusFile *file;
char *screen_string;
char screen_string[32];
GdkScreen *screen;
if (container->details->auto_layout) {
......@@ -955,14 +955,12 @@ handle_local_move (NautilusIconContainer *container,
file = nautilus_file_get_by_uri (item->uri);
screen = gtk_widget_get_screen (GTK_WIDGET (container));
screen_string = g_strdup_printf ("%d",
gdk_screen_get_number (screen));
g_snprintf (screen_string, sizeof (screen_string), "%d",
gdk_screen_get_number (screen));
nautilus_file_set_metadata (file,
NAUTILUS_METADATA_KEY_SCREEN,
NULL, screen_string);
g_free (screen_string);
nautilus_icon_container_add (container,
NAUTILUS_ICON_CONTAINER_ICON_DATA (file),
FALSE);
......
......@@ -3721,7 +3721,7 @@ new_folder_done (const char *new_folder_uri, gpointer user_data)
{
FMDirectoryView *directory_view;
NautilusFile *file;
char *screen_string;
char screen_string[32];
GdkScreen *screen;
NewFolderData *data;
......@@ -3742,14 +3742,13 @@ new_folder_done (const char *new_folder_uri, gpointer user_data)
}
screen = gtk_widget_get_screen (GTK_WIDGET (directory_view));
screen_string = g_strdup_printf ("%d", gdk_screen_get_number (screen));
g_snprintf (screen_string, sizeof (screen_string), "%d", gdk_screen_get_number (screen));
file = nautilus_file_get_by_uri (new_folder_uri);
nautilus_file_set_metadata
(file, NAUTILUS_METADATA_KEY_SCREEN,
NULL,
screen_string);
g_free (screen_string);
if (g_hash_table_lookup_extended (data->added_uris, new_folder_uri, NULL, NULL)) {
/* The file was already added */
......
......@@ -717,14 +717,13 @@ selection_get_cb (GtkWidget *widget,
static GtkWidget *
get_desktop_manager_selection (GdkDisplay *display, int screen)
{
char *selection_name;
char selection_name[32];
GdkAtom selection_atom;
Window selection_owner;
GtkWidget *selection_widget;
selection_name = g_strdup_printf ("_NET_DESKTOP_MANAGER_S%d", screen);
g_snprintf (selection_name, sizeof (selection_name), "_NET_DESKTOP_MANAGER_S%d", screen);
selection_atom = gdk_atom_intern (selection_name, FALSE);
g_free (selection_name);
selection_owner = XGetSelectionOwner (GDK_DISPLAY_XDISPLAY (display),
gdk_x11_atom_to_xatom_for_display (display,
......
......@@ -736,9 +736,9 @@ display_server_uri (NautilusConnectServerDialog *dialog, GnomeVFSURI *uri)
if (meth->flags & SHOW_PORT) {
guint port = gnome_vfs_uri_get_host_port (uri);
if (port != 0) {
char *sport = g_strdup_printf ("%d", port);
char sport[32];
g_snprintf (sport, sizeof (sport), "%d", port);
gtk_entry_set_text (GTK_ENTRY (dialog->details->port_entry), sport);
g_free (sport);
}
}
......
......@@ -540,7 +540,7 @@ receive_dropped_color (NautilusInformationPanel *information_panel,
GtkSelectionData *selection_data)
{
guint16 *channels;
char *color_spec;
char color_spec[8];
if (selection_data->length != 8 || selection_data->format != 16) {
g_warning ("received invalid color data");
......@@ -548,7 +548,8 @@ receive_dropped_color (NautilusInformationPanel *information_panel,
}
channels = (guint16 *) selection_data->data;
color_spec = g_strdup_printf ("#%02X%02X%02X", channels[0] >> 8, channels[1] >> 8, channels[2] >> 8);
g_snprintf (color_spec, sizeof (color_spec),
"#%02X%02X%02X", channels[0] >> 8, channels[1] >> 8, channels[2] >> 8);
switch (hit_test (information_panel, x, y)) {
case NO_PART:
......@@ -570,7 +571,6 @@ receive_dropped_color (NautilusInformationPanel *information_panel,
break;
}
g_free(color_spec);
}
/* handle receiving a dropped keyword */
......
......@@ -1320,17 +1320,17 @@ add_color_to_file (NautilusPropertyBrowser *property_browser, const char *color_
static void
add_color_to_browser (GtkWidget *widget, gint which_button, gpointer *data)
{
char *color_spec;
char color_spec[8];
const char *color_name;
char *stripped_color_name;
gdouble color[4];
NautilusPropertyBrowser *property_browser = NAUTILUS_PROPERTY_BROWSER (data);
if (which_button == GTK_RESPONSE_OK) {
gnome_color_picker_get_d (GNOME_COLOR_PICKER (property_browser->details->color_picker), &color[0], &color[1], &color[2], &color[3]);
color_spec = g_strdup_printf
("#%02X%02X%02X",
g_snprintf (color_spec, sizeof (color_spec),
"#%02X%02X%02X",
(guint) (color[0] * 255.0 + 0.5),
(guint) (color[1] * 255.0 + 0.5),
(guint) (color[2] * 255.0 + 0.5));
......@@ -1347,8 +1347,7 @@ add_color_to_browser (GtkWidget *widget, gint which_button, gpointer *data)
nautilus_property_browser_update_contents(property_browser);
}
g_free (stripped_color_name);
g_free(color_spec);
}
}
gtk_widget_destroy(property_browser->details->colors_dialog);
property_browser->details->colors_dialog = NULL;
......
......@@ -148,7 +148,7 @@ nautilus_window_init (NautilusWindow *window)
GtkWidget *menu;
GtkWidget *statusbar;
window->details = g_new0 (NautilusWindowDetails, 1);
window->details = G_TYPE_INSTANCE_GET_PRIVATE (window, NAUTILUS_TYPE_WINDOW, NautilusWindowDetails);
window->details->show_hidden_files_mode = NAUTILUS_WINDOW_SHOW_HIDDEN_FILES_DEFAULT;
......@@ -638,9 +638,7 @@ nautilus_window_finalize (GObject *object)
}
g_free (window->details->title);
g_free (window->details);
G_OBJECT_CLASS (nautilus_window_parent_class)->finalize (object);
}
......@@ -788,7 +786,8 @@ free_activate_view_data (gpointer data)
activate_data = data;
g_free (activate_data->id);
g_free (activate_data);
g_slice_free (ActivateViewData, activate_data);
}
static void
......@@ -810,16 +809,16 @@ add_view_as_menu_item (NautilusWindow *window,
{
const NautilusViewInfo *info;
GtkRadioAction *action;
char *action_name;
char action_name[32];
ActivateViewData *data;
char *accel;
char *accel_path;
char accel[32];
char accel_path[48];
unsigned int accel_keyval;
info = nautilus_view_factory_lookup (identifier);
action_name = g_strdup_printf ("view_as_%d", index);
g_snprintf (action_name, sizeof (action_name), "view_as_%d", index);
action = gtk_radio_action_new (action_name,
_(info->view_as_label_with_mnemonic),
_(info->display_location_label),
......@@ -827,18 +826,14 @@ add_view_as_menu_item (NautilusWindow *window,
0);
if (index >= 1 && index <= 9) {
accel = g_strdup_printf ("%d", index);
accel_path = g_strdup_printf ("<Nautilus-Window>/%s", action_name);
g_snprintf (accel, sizeof (accel), "%d", index);
g_snprintf (accel_path, sizeof (accel_path), "<Nautilus-Window>/%s", action_name);
accel_keyval = gdk_keyval_from_name (accel);
g_assert (accel_keyval != GDK_VoidSymbol);
gtk_accel_map_add_entry (accel_path, accel_keyval, GDK_CONTROL_MASK);
gtk_action_set_accel_path (GTK_ACTION (action), accel_path);
g_free (accel);
g_free (accel_path);
}
if (window->details->view_as_radio_action != NULL) {
......@@ -850,7 +845,7 @@ add_view_as_menu_item (NautilusWindow *window,
window->details->view_as_radio_action = action;
}
data = g_new (ActivateViewData, 1);
data = g_slice_new (ActivateViewData);
data->window = window;
data->id = g_strdup (identifier);
g_signal_connect_data (action, "activate",
......@@ -868,8 +863,7 @@ add_view_as_menu_item (NautilusWindow *window,
action_name,
GTK_UI_MANAGER_MENUITEM,
FALSE);
g_free (action_name);
return action; /* return value owned by group */
}
......@@ -949,7 +943,7 @@ static void
nautilus_window_synch_view_as_menus (NautilusWindow *window)
{
int index;
char *action_name;
char action_name[32];
GList *node;
GtkAction *action;
......@@ -972,10 +966,9 @@ nautilus_window_synch_view_as_menus (NautilusWindow *window)
remove_extra_viewer_in_view_as_menus (window);
}
action_name = g_strdup_printf ("view_as_%d", index);
g_snprintf (action_name, sizeof (action_name), "view_as_%d", index);
action = gtk_action_group_get_action (window->details->view_as_action_group,
action_name);
g_free (action_name);
/* Don't trigger the action callback when we're synchronizing */
g_signal_handlers_block_matched (action,
......@@ -1692,6 +1685,8 @@ nautilus_window_class_init (NautilusWindowClass *class)
"\n"
" widget \"*.nautilus-extra-view-widget\" style:rc \"nautilus-extra-view-widgets-style-internal\" \n"
"\n");
g_type_class_add_private (G_OBJECT_CLASS (class), sizeof (NautilusWindowDetails));
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment