From 24d8be5ecf2a89ef0523c7002ef2e82c133778f2 Mon Sep 17 00:00:00 2001 From: Huang Peng Date: Tue, 16 Sep 2008 17:28:14 +0800 Subject: [PATCH] Use g_slice_new to replace g_new for better performance. --- client/x11/main.c | 17 ++++++++--------- lib/gtk2/ibusimclient.c | 4 ++-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/client/x11/main.c b/client/x11/main.c index 04bfa74c..0f1cfa6c 100644 --- a/client/x11/main.c +++ b/client/x11/main.c @@ -175,7 +175,7 @@ xim_create_ic (XIMS xims, IMChangeICStruct *call_data) call_data->icid = base_icid ++; - x11ic = g_new0 (X11IC, 1); + x11ic = g_slice_new0 (X11IC); x11ic->icid = call_data->icid; x11ic->connect_id = call_data->connect_id; x11ic->conn = (X11ICONN *)g_hash_table_lookup (_connections, @@ -211,15 +211,14 @@ xim_destroy_ic (XIMS xims, IMChangeICStruct *call_data) (gconstpointer)(unsigned long)call_data->icid); ibus_im_client_release_input_context (_client, x11ic->ibus_ic); - g_hash_table_remove (_ibus_ic_table, x11ic->ibus_ic); - g_free (x11ic->ibus_ic); - - x11ic->conn->clients = g_list_remove (x11ic->conn->clients, (gconstpointer)x11ic); + g_hash_table_remove (_ibus_ic_table, x11ic->ibus_ic); g_hash_table_remove (_x11_ic_table, (gconstpointer)(unsigned long)call_data->icid); + x11ic->conn->clients = g_list_remove (x11ic->conn->clients, (gconstpointer)x11ic); - g_free (x11ic); + g_free (x11ic->ibus_ic); + g_slice_free (X11IC, x11ic); return 1; } @@ -318,7 +317,7 @@ xim_open (XIMS xims, IMOpenStruct *call_data) g_return_val_if_fail (conn == NULL, 1); - conn = g_new0(X11ICONN, 1); + conn = g_slice_new0 (X11ICONN); g_hash_table_insert (_connections, (gpointer)(unsigned long)call_data->connect_id, @@ -342,7 +341,7 @@ _free_ic (gpointer data, gpointer user_data) g_hash_table_remove (_x11_ic_table, (gconstpointer)(unsigned long)x11ic->icid); - g_free (x11ic); + g_slice_free (X11IC, x11ic); } int @@ -365,7 +364,7 @@ xim_close (XIMS ims, IMCloseStruct *call_data) g_hash_table_remove (_connections, (gconstpointer)(unsigned long)call_data->connect_id); - g_free (conn); + g_slice_free (X11ICONN, conn); return 1; } diff --git a/lib/gtk2/ibusimclient.c b/lib/gtk2/ibusimclient.c index 86216201..2d797702 100644 --- a/lib/gtk2/ibusimclient.c +++ b/lib/gtk2/ibusimclient.c @@ -1540,7 +1540,7 @@ struct _KeyPressCallData { static KeyPressCallData * _key_press_call_data_new (IBusIMClient *client, const gchar *ic, GdkEvent *event) { - KeyPressCallData *p = g_new (KeyPressCallData, 1); + KeyPressCallData *p = g_slice_new (KeyPressCallData); p->client = g_object_ref (client); p->ic = g_strdup (ic); p->event = gdk_event_copy (event); @@ -1556,7 +1556,7 @@ _key_press_call_data_free (KeyPressCallData *p) g_free (p->ic); gdk_event_free (p->event); } - g_free (p); + g_slice_free (KeyPressCallData, p); } static void -- 2.34.1