use g_slice_new() instead of g_new() part 3
This commit is contained in:
parent
4f93731cdb
commit
890e13b919
4 changed files with 24 additions and 17 deletions
|
@ -402,7 +402,7 @@ ObtIC* obt_keyboard_context_new(Window client, Window focus)
|
|||
|
||||
g_return_val_if_fail(client != None && focus != None, NULL);
|
||||
|
||||
ic = g_new(ObtIC, 1);
|
||||
ic = g_slice_new(ObtIC);
|
||||
ic->ref = 1;
|
||||
ic->client = client;
|
||||
ic->focus = focus;
|
||||
|
@ -424,6 +424,6 @@ void obt_keyboard_context_unref(ObtIC *ic)
|
|||
if (--ic->ref < 1) {
|
||||
xic_all = g_slist_remove(xic_all, ic);
|
||||
XDestroyIC(ic->xic);
|
||||
g_free(ic);
|
||||
g_slice_free(ObtIC, ic);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -223,7 +223,7 @@ void obt_main_loop_unref(ObtMainLoop *loop)
|
|||
for (it = loop->timers; it; it = g_slist_next(it)) {
|
||||
ObtMainLoopTimer *t = it->data;
|
||||
if (t->destroy) t->destroy(t->data);
|
||||
g_free(t);
|
||||
g_slice_free(ObtMainLoopTimer, t);
|
||||
}
|
||||
g_slist_free(loop->timers);
|
||||
loop->timers = NULL;
|
||||
|
@ -348,7 +348,7 @@ void obt_main_loop_x_add(ObtMainLoop *loop,
|
|||
{
|
||||
ObtMainLoopXHandlerType *h;
|
||||
|
||||
h = g_new(ObtMainLoopXHandlerType, 1);
|
||||
h = g_slice_new(ObtMainLoopXHandlerType);
|
||||
h->loop = loop;
|
||||
h->func = handler;
|
||||
h->data = data;
|
||||
|
@ -377,7 +377,7 @@ void obt_main_loop_x_remove(ObtMainLoop *loop,
|
|||
if (h->func == handler) {
|
||||
loop->x_handlers = g_slist_delete_link(loop->x_handlers, it);
|
||||
if (h->destroy) h->destroy(h->data);
|
||||
g_free(h);
|
||||
g_slice_free(ObtMainLoopXHandlerType, h);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -425,7 +425,7 @@ void obt_main_loop_signal_add(ObtMainLoop *loop,
|
|||
|
||||
g_return_if_fail(signal < NUM_SIGNALS);
|
||||
|
||||
h = g_new(ObtMainLoopSignalHandlerType, 1);
|
||||
h = g_slice_new(ObtMainLoopSignalHandlerType);
|
||||
h->loop = loop;
|
||||
h->signal = signal;
|
||||
h->func = handler;
|
||||
|
@ -473,7 +473,7 @@ void obt_main_loop_signal_remove(ObtMainLoop *loop,
|
|||
g_slist_delete_link(loop->signal_handlers[i], it);
|
||||
if (h->destroy) h->destroy(h->data);
|
||||
|
||||
g_free(h);
|
||||
g_slice_free(ObtMainLoopSignalHandlerType, h);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -505,7 +505,7 @@ void obt_main_loop_fd_add(ObtMainLoop *loop,
|
|||
{
|
||||
ObtMainLoopFdHandlerType *h;
|
||||
|
||||
h = g_new(ObtMainLoopFdHandlerType, 1);
|
||||
h = g_slice_new(ObtMainLoopFdHandlerType);
|
||||
h->loop = loop;
|
||||
h->fd = fd;
|
||||
h->func = handler;
|
||||
|
@ -525,6 +525,7 @@ static void fd_handler_destroy(gpointer data)
|
|||
|
||||
if (h->destroy)
|
||||
h->destroy(h->data);
|
||||
g_slice_free(ObtMainLoopFdHandlerType, h);
|
||||
}
|
||||
|
||||
void obt_main_loop_fd_remove(ObtMainLoop *loop,
|
||||
|
@ -567,7 +568,7 @@ void obt_main_loop_timeout_add(ObtMainLoop *loop,
|
|||
GEqualFunc cmp,
|
||||
GDestroyNotify notify)
|
||||
{
|
||||
ObtMainLoopTimer *t = g_new(ObtMainLoopTimer, 1);
|
||||
ObtMainLoopTimer *t = g_slice_new(ObtMainLoopTimer);
|
||||
|
||||
g_assert(microseconds > 0); /* if it's 0 it'll cause an infinite loop */
|
||||
|
||||
|
@ -655,7 +656,7 @@ static void timer_dispatch(ObtMainLoop *loop, GTimeVal **wait)
|
|||
loop->timers = g_slist_delete_link(loop->timers, it);
|
||||
if (curr->destroy)
|
||||
curr->destroy(curr->data);
|
||||
g_free(curr);
|
||||
g_slice_free(ObtMainLoopTimer, curr);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -676,7 +677,7 @@ static void timer_dispatch(ObtMainLoop *loop, GTimeVal **wait)
|
|||
} else {
|
||||
if (curr->destroy)
|
||||
curr->destroy(curr->data);
|
||||
g_free(curr);
|
||||
g_slice_free(ObtMainLoopTimer, curr);
|
||||
}
|
||||
|
||||
/* the timer queue has been shuffled, start from the beginning
|
||||
|
|
10
obt/xevent.c
10
obt/xevent.c
|
@ -43,6 +43,7 @@ struct _ObtXEventBinding
|
|||
static void xevent_handler(const XEvent *e, gpointer data);
|
||||
static guint window_hash(Window *w) { return *w; }
|
||||
static gboolean window_comp(Window *w1, Window *w2) { return *w1 == *w2; }
|
||||
static void binding_free(gpointer b);
|
||||
|
||||
ObtXEventHandler* xevent_new(void)
|
||||
{
|
||||
|
@ -94,17 +95,22 @@ void xevent_set_handler(ObtXEventHandler *h, gint type, Window win,
|
|||
for (i = h->num_event_types; i < type + 1; ++i)
|
||||
h->bindings[i] = g_hash_table_new_full((GHashFunc)window_hash,
|
||||
(GEqualFunc)window_comp,
|
||||
NULL, g_free);
|
||||
NULL, binding_free);
|
||||
h->num_event_types = type + 1;
|
||||
}
|
||||
|
||||
b = g_new(ObtXEventBinding, 1);
|
||||
b = g_slice_new(ObtXEventBinding);
|
||||
b->win = win;
|
||||
b->func = func;
|
||||
b->data = data;
|
||||
g_hash_table_replace(h->bindings[type], &b->win, b);
|
||||
}
|
||||
|
||||
static void binding_free(gpointer b)
|
||||
{
|
||||
g_slice_free(ObtXEventBinding, b);
|
||||
}
|
||||
|
||||
void xevent_remove_handler(ObtXEventHandler *h, gint type, Window win)
|
||||
{
|
||||
g_assert(type < h->num_event_types);
|
||||
|
|
|
@ -52,12 +52,12 @@ struct _ObtXmlInst {
|
|||
static void destfunc(struct Callback *c)
|
||||
{
|
||||
g_free(c->tag);
|
||||
g_free(c);
|
||||
g_slice_free(struct Callback, c);
|
||||
}
|
||||
|
||||
ObtXmlInst* obt_xml_instance_new(void)
|
||||
{
|
||||
ObtXmlInst *i = g_new(ObtXmlInst, 1);
|
||||
ObtXmlInst *i = g_slice_new(ObtXmlInst);
|
||||
i->ref = 1;
|
||||
i->xdg_paths = obt_paths_new();
|
||||
i->callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
|
||||
|
@ -78,7 +78,7 @@ void obt_xml_instance_unref(ObtXmlInst *i)
|
|||
if (i && --i->ref == 0) {
|
||||
obt_paths_unref(i->xdg_paths);
|
||||
g_hash_table_destroy(i->callbacks);
|
||||
g_free(i);
|
||||
g_slice_free(ObtXmlInst, i);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,7 @@ void obt_xml_register(ObtXmlInst *i, const gchar *tag,
|
|||
return;
|
||||
}
|
||||
|
||||
c = g_new(struct Callback, 1);
|
||||
c = g_slice_new(struct Callback);
|
||||
c->tag = g_strdup(tag);
|
||||
c->func = func;
|
||||
c->data = data;
|
||||
|
|
Loading…
Reference in a new issue