all repos — openbox @ 890e13b919892887b773462bb866e849e0cb4d91

openbox fork - make it a bit more like ryudo

use g_slice_new() instead of g_new() part 3
Dana Jansens danakj@orodu.net
commit

890e13b919892887b773462bb866e849e0cb4d91

parent

4f93731cdbecbf43b82aa000c07ec8b40f97dd03

4 files changed, 24 insertions(+), 17 deletions(-)

jump to
M obt/keyboard.cobt/keyboard.c

@@ -402,7 +402,7 @@ ObtIC *ic;

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 @@ {

if (--ic->ref < 1) { xic_all = g_slist_remove(xic_all, ic); XDestroyIC(ic->xic); - g_free(ic); + g_slice_free(ObtIC, ic); } }
M obt/mainloop.cobt/mainloop.c

@@ -223,7 +223,7 @@

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 @@ GDestroyNotify notify)

{ 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 @@ next = g_slist_next(it);

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 @@ ObtMainLoopSignalHandlerType *h;

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 @@ loop->signal_handlers[i] =

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 @@ GDestroyNotify notify)

{ 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 @@ FD_CLR(h->fd, &h->loop->fd_set);

if (h->destroy) h->destroy(h->data); + g_slice_free(ObtMainLoopFdHandlerType, h); } void obt_main_loop_fd_remove(ObtMainLoop *loop,

@@ -567,7 +568,7 @@ gpointer data,

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 @@ /* delete the top */

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 @@ insert_timer(loop, curr);

} 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
M obt/xevent.cobt/xevent.c

@@ -43,6 +43,7 @@

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,15 +95,20 @@ h->bindings = g_renew(GHashTable*, h->bindings, type + 1);

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)
M obt/xml.cobt/xml.c

@@ -52,12 +52,12 @@

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 @@ {

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 @@ g_error("Tag '%s' already registered", 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;