Skip to content

Commit

Permalink
Use slice allocator instead of g_new when appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse van den Kieboom committed May 10, 2010
1 parent 331af4b commit a0b15be
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
10 changes: 5 additions & 5 deletions plugins/filebrowser/gedit-file-browser-store.c
Expand Up @@ -2333,7 +2333,7 @@ async_node_free (AsyncNode *async)
{
g_object_unref (async->cancellable);
g_slist_free (async->original_children);
g_free (async);
g_slice_free (AsyncNode, async);
}

static void
Expand Down Expand Up @@ -2488,7 +2488,7 @@ model_load_directory (GeditFileBrowserStore *model,

dir->cancellable = g_cancellable_new ();

async = g_new (AsyncNode, 1);
async = g_slice_new (AsyncNode);
async->dir = dir;
async->cancellable = g_object_ref (dir->cancellable);
async->original_children = g_slist_copy (dir->children);
Expand Down Expand Up @@ -2882,7 +2882,7 @@ mount_cb (GFile *file,
g_object_unref (mount_info->virtual_root);
}

g_free (mount_info);
g_slice_free (MountInfo, mount_info);
}

static GeditFileBrowserStoreResult
Expand All @@ -2906,7 +2906,7 @@ model_mount_root (GeditFileBrowserStore *model,
/* Try to mount it */
FILE_BROWSER_NODE_DIR (model->priv->root)->cancellable = g_cancellable_new ();

mount_info = g_new(MountInfo, 1);
mount_info = g_slice_new (MountInfo);
mount_info->model = model;
mount_info->virtual_root = g_file_dup (virtual_root);

Expand Down Expand Up @@ -3617,7 +3617,7 @@ gedit_file_browser_store_delete_all (GeditFileBrowserStore *model,
files = g_list_prepend (files, g_object_ref (node->file));
}

data = g_new (AsyncData, 1);
data = g_slice_new (AsyncData);

data->model = model;
data->cancellable = g_cancellable_new ();
Expand Down
29 changes: 18 additions & 11 deletions plugins/filebrowser/gedit-file-browser-widget.c
Expand Up @@ -252,7 +252,7 @@ free_name_icon (gpointer data)
if (item->icon)
g_object_unref (item->icon);

g_free (item);
g_slice_free (NameIcon, item);
}

static FilterFunc *
Expand All @@ -263,7 +263,7 @@ filter_func_new (GeditFileBrowserWidget *obj,
{
FilterFunc *result;

result = g_new (FilterFunc, 1);
result = g_slice_new (FilterFunc);

result->id = ++obj->priv->filter_id;
result->func = func;
Expand All @@ -281,7 +281,7 @@ location_free (Location *loc)
if (loc->virtual_root)
g_object_unref (loc->virtual_root);

g_free (loc);
g_slice_free (Location, loc);
}

static gboolean
Expand Down Expand Up @@ -332,6 +332,12 @@ cancel_async_operation (GeditFileBrowserWidget *widget)
widget->priv->cancellable = NULL;
}

static void
filter_func_free (FilterFunc *func)
{
g_slice_free (FilterFunc, func);
}

static void
gedit_file_browser_widget_finalize (GObject *object)
{
Expand All @@ -347,7 +353,7 @@ gedit_file_browser_widget_finalize (GObject *object)
g_object_unref (obj->priv->bookmarks_store);
g_object_unref (obj->priv->combo_model);

g_slist_foreach (obj->priv->filter_funcs, (GFunc) g_free, NULL);
g_slist_foreach (obj->priv->filter_funcs, (GFunc)filter_func_free, NULL);
g_slist_free (obj->priv->filter_funcs);

for (loc = obj->priv->locations; loc; loc = loc->next)
Expand Down Expand Up @@ -486,7 +492,7 @@ add_signal (GeditFileBrowserWidget *obj,
gpointer object,
gulong id)
{
SignalNode *node = g_new (SignalNode, 1);
SignalNode *node = g_slice_new (SignalNode);

node->object = G_OBJECT (object);
node->id = id;
Expand All @@ -506,7 +512,7 @@ clear_signals (GeditFileBrowserWidget *obj)
node = (SignalNode *) (item->data);

g_signal_handler_disconnect (node->object, node->id);
g_free (item->data);
g_slice_free (SignalNode, node);
}

g_slist_free (obj->priv->signal_pool);
Expand Down Expand Up @@ -1104,7 +1110,7 @@ add_bookmark_hash (GeditFileBrowserWidget *obj,
GEDIT_FILE_BOOKMARKS_STORE_COLUMN_NAME,
&name, -1);

item = g_new (NameIcon, 1);
item = g_slice_new (NameIcon);
item->name = name;
item->icon = pixbuf;

Expand Down Expand Up @@ -2009,7 +2015,8 @@ gedit_file_browser_widget_remove_filter (GeditFileBrowserWidget *obj,
obj->priv->filter_funcs =
g_slist_remove_link (obj->priv->filter_funcs,
item);
g_free (func);

filter_func_free (func);
break;
}
}
Expand Down Expand Up @@ -2116,7 +2123,7 @@ async_data_new (GeditFileBrowserWidget *widget)
{
AsyncData *ret;

ret = g_new (AsyncData, 1);
ret = g_slice_new (AsyncData);
ret->widget = widget;

cancel_async_operation (widget);
Expand All @@ -2131,7 +2138,7 @@ static void
async_free (AsyncData *async)
{
g_object_unref (async->cancellable);
g_free (async);
g_slice_free (AsyncData, async);
}

static void
Expand Down Expand Up @@ -2606,7 +2613,7 @@ on_virtual_root_changed (GeditFileBrowserStore *model,
if (obj->priv->current_location)
clear_next_locations (obj);

loc = g_new (Location, 1);
loc = g_slice_new (Location);
loc->root = gedit_file_browser_store_get_root (model);
loc->virtual_root = g_object_ref (location);

Expand Down

0 comments on commit a0b15be

Please sign in to comment.