Changeset 7dcef03


Ignore:
Timestamp:
Dec 25, 2013, 11:33:37 AM (4 years ago)
Author:
Anders Kaseorg <andersk@mit.edu>
Branches:
master
Children:
8f95fc4, db1a2f8b, c53f5e8, 1bd5aa9
Parents:
d779a1a
git-author:
Anders Kaseorg <andersk@mit.edu> (12/25/13 11:18:38)
git-committer:
Anders Kaseorg <andersk@mit.edu> (12/25/13 11:33:37)
Message:
Use the Glib slice allocator for fixed-size objects

The slice allocator, available since GLib 2.10, is more
space-efficient than [g_]malloc.  Since BarnOwl is obviously at the
leading edge of space-efficient technology, this seems like a natural
fit.  Use it for every fixed-size object except
owl_viewwin_search_data (which would need an extra destroy_cbdata
function to g_slice_free it).

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
Files:
27 edited

Legend:

Unmodified
Added
Removed
  • aim.c

    r8258ea5 r7dcef03  
    10491049  wrapmsg=owl_text_wordwrap(stripmsg, 70);
    10501050  nz_screenname=owl_aim_normalize_screenname(userinfo->sn);
    1051   m=g_new(owl_message, 1);
     1051  m=g_slice_new(owl_message);
    10521052  owl_message_create_aim(m,
    10531053                         nz_screenname,
  • buddy.c

    rd4927a7 r7dcef03  
    7272{
    7373  owl_buddy_cleanup(b);
    74   g_free(b);
     74  g_slice_free(owl_buddy, b);
    7575}
  • buddylist.c

    r3cdd6d2 r7dcef03  
    1111{
    1212  owl_buddy *b;
    13   b=g_new(owl_buddy, 1);
     13  b=g_slice_new(owl_buddy);
    1414 
    1515  owl_buddy_create(b, OWL_PROTOCOL_AIM, screenname);
     
    5050
    5151    /* if not, create the login message */
    52     m=g_new(owl_message, 1);
     52    m=g_slice_new(owl_message);
    5353    owl_message_create_aim(m,
    5454                           screenname,
     
    6969
    7070  if (owl_buddylist_is_aim_buddy_loggedin(bl, screenname)) {
    71     m=g_new(owl_message, 1);
     71    m=g_slice_new(owl_message);
    7272    owl_message_create_aim(m,
    7373                           screenname,
  • cmd.c

    rf271129 r7dcef03  
    3535void owl_cmddict_add_alias(owl_cmddict *cd, const char *alias_from, const char *alias_to) {
    3636  owl_cmd *cmd;
    37   cmd = g_new(owl_cmd, 1);
     37  cmd = g_slice_new(owl_cmd);
    3838  owl_cmd_create_alias(cmd, alias_from, alias_to);
    3939  owl_perlconfig_new_command(cmd->name);
     
    4242
    4343int owl_cmddict_add_cmd(owl_cmddict *cd, const owl_cmd * cmd) {
    44   owl_cmd * newcmd = g_new(owl_cmd, 1);
     44  owl_cmd * newcmd = g_slice_new(owl_cmd);
    4545  if(owl_cmd_create_from_template(newcmd, cmd) < 0) {
    46     g_free(newcmd);
     46    g_slice_free(owl_cmd, newcmd);
    4747    return -1;
    4848  }
     
    141141{
    142142  owl_cmd_cleanup(cmd);
    143   g_free(cmd);
     143  g_slice_free(owl_cmd, cmd);
    144144}
    145145
  • context.c

    rf271129 r7dcef03  
    1010  if (!(mode & OWL_CTX_MODE_BITS))
    1111    mode |= OWL_CTX_INTERACTIVE;
    12   c = g_new0(owl_context, 1);
     12  c = g_slice_new0(owl_context);
    1313  c->mode = mode;
    1414  c->data = data;
     
    7171  if (ctx->delete_cb)
    7272    ctx->delete_cb(ctx);
    73   g_free(ctx);
     73  g_slice_free(owl_context, ctx);
    7474}
  • editwin.c

    r8258ea5 r7dcef03  
    6868static CALLER_OWN owl_editwin *owl_editwin_allocate(void)
    6969{
    70   owl_editwin *e = g_new0(owl_editwin, 1);
     70  owl_editwin *e = g_slice_new0(owl_editwin);
    7171  e->refcount = 1;
    7272  return e;
     
    8787  oe_destroy_cbdata(e);
    8888
    89   g_free(e);
     89  g_slice_free(owl_editwin, e);
    9090}
    9191
     
    373373owl_editwin_excursion *owl_editwin_begin_excursion(owl_editwin *e)
    374374{
    375   owl_editwin_excursion *x = g_new(owl_editwin_excursion, 1);
     375  owl_editwin_excursion *x = g_slice_new(owl_editwin_excursion);
    376376  oe_save_excursion(e, x);
    377377  return x;
     
    381381{
    382382  oe_restore_excursion(e, x);
    383   g_free(x);
     383  g_slice_free(owl_editwin_excursion, x);
    384384}
    385385
  • filter.c

    rc068c03 r7dcef03  
    1818  owl_filter *f;
    1919
    20   f = g_new(owl_filter, 1);
     20  f = g_slice_new(owl_filter);
    2121
    2222  f->name=g_strdup(name);
     
    6969  if(!argc) return NULL;
    7070
    71   fe = g_new(owl_filterelement, 1);
     71  fe = g_slice_new(owl_filterelement);
    7272  owl_filterelement_create(fe);
    7373
     
    114114err:
    115115  owl_filterelement_cleanup(fe);
    116   g_free(fe);
     116  g_slice_free(owl_filterelement, fe);
    117117  return NULL;
    118118}
     
    132132    op2 = owl_filter_parse_primitive_expression(argc-i-1, argv+i+1, &skip);
    133133    if(!op2) goto err;
    134     tmp = g_new(owl_filterelement, 1);
     134    tmp = g_slice_new(owl_filterelement);
    135135    if(!strcasecmp(argv[i], "and")) {
    136136      owl_filterelement_create_and(tmp, op1, op2);
     
    152152  if(op1) {
    153153    owl_filterelement_cleanup(op1);
    154     g_free(op1);
     154    g_slice_free(owl_filterelement, op1);
    155155  }
    156156  return NULL;
     
    262262  if (f->root) {
    263263    owl_filterelement_cleanup(f->root);
    264     g_free(f->root);
     264    g_slice_free(owl_filterelement, f->root);
    265265  }
    266266  if (f->name)
    267267    g_free(f->name);
    268   g_free(f);
    269 }
     268  g_slice_free(owl_filter, f);
     269}
  • filterelement.c

    r7756dde r7dcef03  
    328328  if (fe->left) {
    329329    owl_filterelement_cleanup(fe->left);
    330     g_free(fe->left);
     330    g_slice_free(owl_filterelement, fe->left);
    331331  }
    332332  if (fe->right) {
    333333    owl_filterelement_cleanup(fe->right);
    334     g_free(fe->right);
     334    g_slice_free(owl_filterelement, fe->right);
    335335  }
    336336  owl_regex_cleanup(&(fe->re));
  • functions.c

    rc55930e r7dcef03  
    196196  owl_message *m;
    197197
    198   m=g_new(owl_message, 1);
     198  m=g_slice_new(owl_message);
    199199  owl_message_create_admin(m, header, body);
    200200 
     
    218218  if (z->cc && owl_zwrite_is_personal(z)) {
    219219    /* create the message */
    220     owl_message *m = g_new(owl_message, 1);
     220    owl_message *m = g_slice_new(owl_message);
    221221    owl_message_create_from_zwrite(m, z, owl_zwrite_get_message(z), 0);
    222222
     
    231231
    232232      /* create the message */
    233       m = g_new(owl_message, 1);
     233      m = g_slice_new(owl_message);
    234234      owl_message_create_from_zwrite(m, z, owl_zwrite_get_message(z), i);
    235235
     
    251251  if (!owl_global_is_aimloggedin(&g)) return(NULL);
    252252 
    253   m=g_new(owl_message, 1);
     253  m=g_slice_new(owl_message);
    254254  owl_message_create_aim(m,
    255255                         owl_global_get_aim_screenname(&g),
     
    270270
    271271  /* create the message */
    272   m=g_new(owl_message, 1);
     272  m=g_slice_new(owl_message);
    273273  owl_message_create_loopback(m, body);
    274274  owl_message_set_direction_out(m);
     
    516516  /* create a message and put it on the message queue.  This simulates
    517517   * an incoming message */
    518   min=g_new(owl_message, 1);
     518  min=g_slice_new(owl_message);
    519519  mout=owl_function_make_outgoing_loopback(msg);
    520520
     
    34823482  while (zaldptr) {
    34833483    ZFreeALD(zaldptr->data);
    3484     g_free(zaldptr->data);
     3484    g_slice_free(ZAsyncLocateData_t, zaldptr->data);
    34853485    zaldptr = g_list_next(zaldptr);
    34863486  }
     
    34923492    for (i = 0; i < anyone->len; i++) {
    34933493      user = anyone->pdata[i];
    3494       zald = g_new(ZAsyncLocateData_t, 1);
     3494      zald = g_slice_new(ZAsyncLocateData_t);
    34953495      if (ZRequestLocations(zstr(user), zald, UNACKED, ZAUTH) == ZERR_NONE) {
    34963496        *zaldlist = g_list_append(*zaldlist, zald);
    34973497      } else {
    3498         g_free(zald);
     3498        g_slice_free(ZAsyncLocateData_t, zald);
    34993499      }
    35003500    }
  • global.c

    r120dac7 r7dcef03  
    553553  e->g->filterlist = g_list_remove(e->g->filterlist, e->f);
    554554  owl_filter_delete(e->f);
    555   g_free(e);
     555  g_slice_free(owl_global_filter_ent, e);
    556556}
    557557
    558558void owl_global_add_filter(owl_global *g, owl_filter *f) {
    559   owl_global_filter_ent *e = g_new(owl_global_filter_ent, 1);
     559  owl_global_filter_ent *e = g_slice_new(owl_global_filter_ent);
    560560  e->g = g;
    561561  e->f = f;
  • keybinding.c

    rf271129 r7dcef03  
    1414CALLER_OWN owl_keybinding *owl_keybinding_new(const char *keyseq, const char *command, void (*function_fn)(void), const char *desc)
    1515{
    16   owl_keybinding *kb = g_new(owl_keybinding, 1);
     16  owl_keybinding *kb = g_slice_new(owl_keybinding);
    1717
    1818  owl_function_debugmsg("owl_keybinding_init: creating binding for <%s> with desc: <%s>", keyseq, desc);
    1919  if (command && function_fn) {
    20     g_free(kb);
     20    g_slice_free(owl_keybinding, kb);
    2121    return NULL;
    2222  } else if (command && !function_fn) {
     
    2929
    3030  if (owl_keybinding_make_keys(kb, keyseq) != 0) {
    31     g_free(kb);
     31    g_slice_free(owl_keybinding, kb);
    3232    return NULL;
    3333  }
     
    7070  g_free(kb->desc);
    7171  g_free(kb->command);
    72   g_free(kb);
     72  g_slice_free(owl_keybinding, kb);
    7373}
    7474
  • keymap.c

    rf271129 r7dcef03  
    189189{
    190190  owl_keymap *km;
    191   km = g_new(owl_keymap, 1);
     191  km = g_slice_new(owl_keymap);
    192192  owl_keymap_init(km, name, desc, default_fn, prealways_fn, postalways_fn);
    193193  owl_keyhandler_add_keymap(kh, km);
  • logging.c

    r0792d99 r7dcef03  
    177177    g_free(msg->message);
    178178    g_free(msg->filename);
    179     g_free(msg);
     179    g_slice_free(owl_log_entry, msg);
    180180  }
    181181}
     
    184184{
    185185  owl_log_entry *log_msg = NULL;
    186   log_msg = g_new(owl_log_entry,1);
     186  log_msg = g_slice_new(owl_log_entry);
    187187  log_msg->message = g_strdup(buffer);
    188188  log_msg->filename = g_strdup(filename);
     
    266266   * owl_log_shouldlog_message(void)
    267267   */
    268   m = g_new(owl_message, 1);
     268  m = g_slice_new(owl_message);
    269269  /* recip_index = 0 because there can only be one recipient anyway */
    270270  owl_message_create_from_zwrite(m, zw, text, 0);
  • mainwin.c

    rab88b05 r7dcef03  
    66CALLER_OWN owl_mainwin *owl_mainwin_new(owl_window *window)
    77{
    8   owl_mainwin *mw = g_new(owl_mainwin, 1);
     8  owl_mainwin *mw = g_slice_new(owl_mainwin);
    99  mw->curtruncated=0;
    1010  mw->lastdisplayed=-1;
  • message.c

    r2354e9a r7dcef03  
    7070
    7171  if(pair ==  NULL) {
    72     pair = g_new(owl_pair, 1);
     72    pair = g_slice_new(owl_pair);
    7373    owl_pair_create(pair, attrname, NULL);
    7474    g_ptr_array_add(m->attributes, pair);
     
    10191019    p = m->attributes->pdata[i];
    10201020    g_free(owl_pair_get_value(p));
    1021     g_free(p);
     1021    g_slice_free(owl_pair, p);
    10221022  }
    10231023
     
    10301030{
    10311031  owl_message_cleanup(m);
    1032   g_free(m);
    1033 }
     1032  g_slice_free(owl_message, m);
     1033}
  • messagelist.c

    r219f52c r7dcef03  
    33CALLER_OWN owl_messagelist *owl_messagelist_new(void)
    44{
    5   owl_messagelist *ml = g_new(owl_messagelist, 1);
     5  owl_messagelist *ml = g_slice_new(owl_messagelist);
    66  ml->list = g_ptr_array_new();
    77  return ml;
     
    1313    g_ptr_array_foreach(ml->list, (GFunc)owl_message_delete, NULL);
    1414  g_ptr_array_free(ml->list, true);
    15   g_free(ml);
     15  g_slice_free(owl_messagelist, ml);
    1616}
    1717
  • perlconfig.c

    rca1fb26a r7dcef03  
    188188  hash = (HV*)SvRV(msg);
    189189
    190   m = g_new(owl_message, 1);
     190  m = g_slice_new(owl_message);
    191191  owl_message_init(m);
    192192
  • perlglue.xs

    rae2b830 r7dcef03  
    232232     CODE:
    233233        {
    234                 s = g_new(owl_style, 1);
     234                s = g_slice_new(owl_style);
    235235                owl_style_create_perl(s, name, newSVsv(object));
    236236                owl_global_add_style(&g, s);
  • popexec.c

    re146cd7 r7dcef03  
    2323  }
    2424
    25   pe = g_new(owl_popexec, 1);
     25  pe = g_slice_new(owl_popexec);
    2626  pe->winactive=0;
    2727  pe->pid=0;
     
    179179  if (pe->refcount<=0) {
    180180    owl_function_debugmsg("doing free of %p", pe);
    181     g_free(pe);
     181    g_slice_free(owl_popexec, pe);
    182182  }
    183183}
  • popwin.c

    r6829afc r7dcef03  
    33CALLER_OWN owl_popwin *owl_popwin_new(void)
    44{
    5   owl_popwin *pw = g_new0(owl_popwin, 1);
     5  owl_popwin *pw = g_slice_new0(owl_popwin);
    66
    77  pw->border = owl_window_new(NULL);
     
    9292  g_object_unref(pw->content);
    9393
    94   g_free(pw);
     94  g_slice_free(owl_popwin, pw);
    9595}
    9696
  • runtests.sh

    r5db8835 r7dcef03  
    11#!/bin/sh
     2export G_SLICE=debug-blocks
    23exec env HARNESS_PERL=./tester prove --failures "${srcdir:=$(dirname "$0")}/t/"
  • select.c

    r84a071f r7dcef03  
    4141  if (t->destroy_cbdata)
    4242    t->destroy_cbdata(t->cbdata);
    43   g_free(t);
     43  g_slice_free(owl_task, t);
    4444}
    4545
     
    4747{
    4848  GSource *source = g_idle_source_new();
    49   owl_task *t = g_new0(owl_task, 1);
     49  owl_task *t = g_slice_new0(owl_task);
    5050  t->cb = cb;
    5151  t->cbdata = cbdata;
  • style.c

    r92ffd89 r7dcef03  
    103103{
    104104  owl_style_cleanup(s);
    105   g_free(s);
     105  g_slice_free(owl_style, s);
    106106}
  • variable.c

    r9d4dfdc r7dcef03  
    627627
    628628static owl_variable *owl_variable_newvar(int type, const char *name, const char *summary, const char *description, const char *validsettings) {
    629   owl_variable *var = g_new0(owl_variable, 1);
     629  owl_variable *var = g_slice_new0(owl_variable);
    630630  var->type = type;
    631631  var->name = g_strdup(name);
     
    793793  g_closure_unref(v->set_fromstring_fn);
    794794
    795   g_free(v);
     795  g_slice_free(owl_variable, v);
    796796}
    797797
  • viewwin.c

    r7803326 r7dcef03  
    1313CALLER_OWN owl_viewwin *owl_viewwin_new_text(owl_window *win, const char *text)
    1414{
    15   owl_viewwin *v = g_new0(owl_viewwin, 1);
     15  owl_viewwin *v = g_slice_new0(owl_viewwin);
    1616  owl_fmtext_init_null(&(v->fmtext));
    1717  if (text) {
     
    3636{
    3737  char *text;
    38   owl_viewwin *v = g_new0(owl_viewwin, 1);
     38  owl_viewwin *v = g_slice_new0(owl_viewwin);
    3939
    4040  owl_fmtext_copy(&(v->fmtext), fmtext);
     
    424424  g_object_unref(v->status);
    425425  owl_fmtext_cleanup(&(v->fmtext));
    426   g_free(v);
    427 }
     426  g_slice_free(owl_viewwin, v);
     427}
  • zephyr.c

    rebcdf4d r7dcef03  
    125125    owl_zephyr_loadsubs_helper(subs->subs, subs->nsubs);
    126126    deferred_subs = g_list_delete_link(deferred_subs, deferred_subs);
    127     g_free(subs);
     127    g_slice_free(owl_sub_list, subs);
    128128  }
    129129
     
    261261    g_free(subs);
    262262  } else {
    263     owl_sub_list *s = g_new(owl_sub_list, 1);
     263    owl_sub_list *s = g_slice_new(owl_sub_list);
    264264    s->subs = subs;
    265265    s->nsubs = count;
     
    14131413          if (ret == ZERR_NONE) {
    14141414            /* Send a PSEUDO LOGIN! */
    1415             m = g_new(owl_message, 1);
     1415            m = g_slice_new(owl_message);
    14161416            owl_message_create_pseudo_zlogin(m, 0, zald->user,
    14171417                                             location.host,
     
    14261426        /* Send a PSEUDO LOGOUT! */
    14271427        if (notify) {
    1428           m = g_new(owl_message, 1);
     1428          m = g_slice_new(owl_message);
    14291429          owl_message_create_pseudo_zlogin(m, 1, zald->user, "", "", "");
    14301430          owl_global_messagequeue_addmsg(&g, m);
     
    14351435    }
    14361436    ZFreeALD(zald);
    1437     g_free(zald);
     1437    g_slice_free(ZAsyncLocateData_t, zald);
    14381438  }
    14391439}
     
    15021502
    15031503      /* create the new message */
    1504       m=g_new(owl_message, 1);
     1504      m=g_slice_new(owl_message);
    15051505      owl_message_create_from_znotice(m, &notice);
    15061506
  • zwrite.c

    r919cbf2 r7dcef03  
    33CALLER_OWN owl_zwrite *owl_zwrite_new_from_line(const char *line)
    44{
    5   owl_zwrite *z = g_new(owl_zwrite, 1);
     5  owl_zwrite *z = g_slice_new(owl_zwrite);
    66  if (owl_zwrite_create_from_line(z, line) != 0) {
    7     g_free(z);
     7    g_slice_free(owl_zwrite, z);
    88    return NULL;
    99  }
     
    1313CALLER_OWN owl_zwrite *owl_zwrite_new(int argc, const char *const *argv)
    1414{
    15   owl_zwrite *z = g_new(owl_zwrite, 1);
     15  owl_zwrite *z = g_slice_new(owl_zwrite);
    1616  if (owl_zwrite_create(z, argc, argv) != 0) {
    17     g_free(z);
     17    g_slice_free(owl_zwrite, z);
    1818    return NULL;
    1919  }
     
    356356{
    357357  owl_zwrite_cleanup(z);
    358   g_free(z);
     358  g_slice_free(owl_zwrite, z);
    359359}
    360360
Note: See TracChangeset for help on using the changeset viewer.