[patch] [bug 461795] reduce some small allocations
- From: Christian Persch <chpe gnome org>
- To: nautilus-list gnome org
- Subject: [patch] [bug 461795] reduce some small allocations
- Date: Mon, 03 Dec 2007 13:52:35 +0100
Hi;
attached patch from bug http://bugzilla.gnome.org/show_bug.cgi?id=461795
removes some small allocations, and makes other use GSlice.
Ok to commit?
Christian
Index: src/nautilus-application.c
===================================================================
--- src/nautilus-application.c (révision 13473)
+++ src/nautilus-application.c (copie de travail)
@@ -717,14 +717,13 @@ selection_get_cb (GtkWidget *wi
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,
Index: src/nautilus-information-panel.c
===================================================================
--- src/nautilus-information-panel.c (révision 13473)
+++ src/nautilus-information-panel.c (copie de travail)
@@ -540,7 +540,7 @@ receive_dropped_color (NautilusInformati
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 (NautilusInformati
}
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 (NautilusInformati
break;
}
- g_free(color_spec);
}
/* handle receiving a dropped keyword */
Index: src/file-manager/fm-directory-view.c
===================================================================
--- src/file-manager/fm-directory-view.c (révision 13473)
+++ src/file-manager/fm-directory-view.c (copie de travail)
@@ -3721,7 +3721,7 @@ new_folder_done (const char *new_folder_
{
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_
}
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 */
Index: src/nautilus-property-browser.c
===================================================================
--- src/nautilus-property-browser.c (révision 13473)
+++ src/nautilus-property-browser.c (copie de travail)
@@ -1320,17 +1320,17 @@ add_color_to_file (NautilusPropertyBrows
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,
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;
Index: src/nautilus-window.c
===================================================================
--- src/nautilus-window.c (révision 13473)
+++ src/nautilus-window.c (copie de travail)
@@ -148,7 +148,7 @@ nautilus_window_init (NautilusWindow *wi
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 *objec
}
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 *w
{
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 *w
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 *w
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 *w
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 (Nau
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 (NautilusWind
"\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));
}
/**
Index: src/nautilus-connect-server-dialog.c
===================================================================
--- src/nautilus-connect-server-dialog.c (révision 13473)
+++ src/nautilus-connect-server-dialog.c (copie de travail)
@@ -736,9 +736,9 @@ display_server_uri (NautilusConnectServe
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);
}
}
Index: libnautilus-private/nautilus-file-operations-progress.c
===================================================================
--- libnautilus-private/nautilus-file-operations-progress.c (révision 13473)
+++ libnautilus-private/nautilus-file-operations-progress.c (copie de travail)
@@ -441,7 +441,7 @@ time_remaining_callback (gpointer callba
/* 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)"),
Index: libnautilus-private/nautilus-directory.c
===================================================================
--- libnautilus-private/nautilus-directory.c (révision 13473)
+++ libnautilus-private/nautilus-directory.c (copie de travail)
@@ -1593,8 +1593,7 @@ nautilus_directory_schedule_position_set
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
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);
}
Index: libnautilus-private/nautilus-icon-dnd.c
===================================================================
--- libnautilus-private/nautilus-icon-dnd.c (révision 13473)
+++ libnautilus-private/nautilus-icon-dnd.c (copie de travail)
@@ -928,7 +928,7 @@ handle_local_move (NautilusIconContainer
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
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);
Index: libnautilus-private/nautilus-dnd.c
===================================================================
--- libnautilus-private/nautilus-dnd.c (révision 13473)
+++ libnautilus-private/nautilus-dnd.c (copie de travail)
@@ -427,13 +427,11 @@ add_one_gnome_icon (const char *uri, int
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);
}
/*
Index: libnautilus-private/nautilus-directory-metafile.c
===================================================================
--- libnautilus-private/nautilus-directory-metafile.c (révision 13473)
+++ libnautilus-private/nautilus-directory-metafile.c (copie de travail)
@@ -429,11 +429,11 @@ nautilus_directory_get_integer_file_meta
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_meta
g_free (result_as_string);
}
- g_free (default_as_string);
return result;
}
@@ -460,18 +459,15 @@ nautilus_directory_set_integer_file_meta
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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]