Changeset a387d12e


Ignore:
Timestamp:
Mar 27, 2007, 10:04:10 PM (17 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, barnowl_perlaim, debian, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
61abb18
Parents:
702aee7
git-author:
Nelson Elhage <nelhage@mit.edu> (03/27/07 22:04:03)
git-committer:
Nelson Elhage <nelhage@mit.edu> (03/27/07 22:04:10)
Message:
Implementing an LRU cache of the message list fmtexts. This reduces
memory usage by roughly 1MB/kilo-zephyrs in steady state.
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • fmtext.c

    r801b7ac ra387d12e  
    99{
    1010  f->textlen=0;
    11   f->textbuff=owl_strdup("");
     11  f->bufflen=5;
     12  f->textbuff=owl_malloc(5);
    1213  f->fmbuff=owl_malloc(5);
    1314  f->fgcolorbuff=owl_malloc(5);
    1415  f->bgcolorbuff=owl_malloc(5);
     16  f->textbuff[0]=0;
    1517  f->fmbuff[0]=OWL_FMTEXT_ATTR_NONE;
    1618  f->fgcolorbuff[0]=OWL_COLOR_DEFAULT;
     
    1820}
    1921
     22/* Clear the data from an fmtext, but don't deallocate memory. This
     23   fmtext can then be appended to again. */
     24void owl_fmtext_clear(owl_fmtext *f)
     25{
     26    f->textlen = 0;
     27    f->textbuff[0] = 0;
     28    f->fmbuff[0]=OWL_FMTEXT_ATTR_NONE;
     29    f->fgcolorbuff[0]=OWL_COLOR_DEFAULT;
     30    f->bgcolorbuff[0]=OWL_COLOR_DEFAULT;
     31}
     32
    2033/* Internal function.  Set the attribute 'attr' from index 'first' to
    2134 * index 'last'
     
    5972}
    6073
     74void _owl_fmtext_realloc(owl_fmtext *f, int newlen) /*noproto*/
     75{
     76    if(newlen + 1 > f->bufflen) {
     77      f->textbuff=owl_realloc(f->textbuff, newlen+1);
     78      f->fmbuff=owl_realloc(f->fmbuff, newlen+1);
     79      f->fgcolorbuff=owl_realloc(f->fgcolorbuff, newlen+1);
     80      f->bgcolorbuff=owl_realloc(f->bgcolorbuff, newlen+1);
     81      f->bufflen = newlen+1;
     82  }
     83}
     84
    6185/* append text to the end of 'f' with attribute 'attr' and color
    6286 * 'color'
     
    6589{
    6690  int newlen;
    67 
    6891  newlen=strlen(f->textbuff)+strlen(text);
    69   f->textbuff=owl_realloc(f->textbuff, newlen+2);
    70   f->fmbuff=owl_realloc(f->fmbuff, newlen+2);
    71   f->fgcolorbuff=owl_realloc(f->fgcolorbuff, newlen+2);
    72   f->bgcolorbuff=owl_realloc(f->bgcolorbuff, newlen+2);
    73 
     92  _owl_fmtext_realloc(f, newlen);
     93 
    7494  strcat(f->textbuff, text);
    7595  _owl_fmtext_set_attr(f, attr, f->textlen, newlen);
     
    154174
    155175  newlen=strlen(f->textbuff)+(stop-start+1);
    156   f->textbuff=owl_realloc(f->textbuff, newlen+1);
    157   f->fmbuff=owl_realloc(f->fmbuff, newlen+1);
    158   f->fgcolorbuff=owl_realloc(f->fgcolorbuff, newlen+1);
    159   f->bgcolorbuff=owl_realloc(f->bgcolorbuff, newlen+1);
     176  _owl_fmtext_realloc(f, newlen);
    160177
    161178  strncat(f->textbuff, in->textbuff+start, stop-start+1);
  • global.c

    r8e401cae ra387d12e  
    108108
    109109  owl_obarray_init(&(g->obarray));
     110
     111  owl_message_init_fmtext_cache();
    110112}
    111113
  • message.c

    r963542b ra387d12e  
    1313static const char fileIdent[] = "$Id$";
    1414
     15static owl_fmtext_cache fmtext_cache[OWL_FMTEXT_CACHE_SIZE];
     16static owl_fmtext_cache * fmtext_cache_next = fmtext_cache;
     17
     18void owl_message_init_fmtext_cache ()
     19{
     20    int i;
     21    for(i = 0; i < OWL_FMTEXT_CACHE_SIZE; i++) {
     22        owl_fmtext_init_null(&(fmtext_cache[i].fmtext));
     23        fmtext_cache[i].message = NULL;
     24    }
     25}
     26
     27owl_fmtext_cache * owl_message_next_fmtext() /*noproto*/
     28{
     29    if(fmtext_cache_next->message != NULL) {
     30        owl_message_invalidate_format(fmtext_cache_next->message);
     31    }
     32    owl_fmtext_cache * f = fmtext_cache_next;
     33    fmtext_cache_next++;
     34    if(fmtext_cache_next - fmtext_cache == OWL_FMTEXT_CACHE_SIZE)
     35        fmtext_cache_next = fmtext_cache;
     36    return f;
     37}
     38
    1539void owl_message_init(owl_message *m)
    1640{
     
    1943  m->delete=0;
    2044  m->zwriteline=NULL;
    21   m->invalid_format=1;
    2245
    2346  owl_message_set_hostname(m, "");
     
    2952  m->timestr[strlen(m->timestr)-1]='\0';
    3053
    31   /* initialize the fmtext */
    32   owl_fmtext_init_null(&(m->fmtext));
     54  m->fmtext = NULL;
    3355}
    3456
     
    106128void owl_message_invalidate_format(owl_message *m)
    107129{
    108   m->invalid_format=1;
     130  if(m->fmtext) {
     131    m->fmtext->message = NULL;
     132    owl_fmtext_clear(&(m->fmtext->fmtext));
     133    m->fmtext=NULL;
     134  }
    109135}
    110136
     
    112138{
    113139  owl_message_format(m);
    114   return(&(m->fmtext));
     140  return(&(m->fmtext->fmtext));
    115141}
    116142
     
    120146  owl_view *v;
    121147
    122   if (m->invalid_format) {
     148  if (!m->fmtext) {
     149    m->fmtext = owl_message_next_fmtext();
     150    m->fmtext->message = m;
    123151    /* for now we assume there's just the one view and use that style */
    124152    v=owl_global_get_current_view(&g);
    125153    s=owl_view_get_style(v);
    126154
    127     owl_fmtext_free(&(m->fmtext));
    128     owl_fmtext_init_null(&(m->fmtext));
    129     owl_style_get_formattext(s, &(m->fmtext), m);
    130     m->invalid_format=0;
     155    owl_style_get_formattext(s, &(m->fmtext->fmtext), m);
    131156  }
    132157}
     
    392417char *owl_message_get_text(owl_message *m)
    393418{
    394   return(owl_fmtext_get_text(&(m->fmtext)));
     419  return(owl_fmtext_get_text(&(m->fmtext->fmtext)));
    395420}
    396421
     
    437462  if (m == NULL) return(0);
    438463  owl_message_format(m);
    439   return(owl_fmtext_num_lines(&(m->fmtext)));
     464  return(owl_fmtext_num_lines(&(m->fmtext->fmtext)));
    440465}
    441466
     
    504529  owl_fmtext_init_null(&b);
    505530 
    506   owl_fmtext_truncate_lines(&(m->fmtext), aline, bline-aline+1, &a);
     531  owl_fmtext_truncate_lines(&(m->fmtext->fmtext), aline, bline-aline+1, &a);
    507532  owl_fmtext_truncate_cols(&a, acol, bcol, &b);
    508533  if (fgcolor!=OWL_COLOR_DEFAULT) {
     
    698723  owl_message_format(m); /* is this necessary? */
    699724 
    700   return (owl_fmtext_search(&(m->fmtext), string));
     725  return (owl_fmtext_search(&(m->fmtext->fmtext), string));
    701726}
    702727
     
    9891014  owl_list_free_simple(&(m->attributes));
    9901015 
    991   owl_fmtext_free(&(m->fmtext));
    992 }
     1016  owl_message_invalidate_format(m);
     1017}
  • owl.h

    rd08162a ra387d12e  
    249249typedef struct _owl_fmtext {
    250250  int textlen;
     251  int bufflen;
    251252  char *textbuff;
    252253  char *fmbuff;
     
    329330} owl_pair;
    330331
     332struct _owl_fmtext_cache;
     333
    331334typedef struct _owl_message {
    332335  int id;
     
    335338  ZNotice_t notice;
    336339#endif
    337   owl_fmtext fmtext;              /* this is now only a CACHED copy */
    338   int invalid_format;             /* indicates whether fmtext needs to be regenerated */
     340  struct _owl_fmtext_cache * fmtext;
    339341  int delete;
    340342  char *hostname;
     
    344346  char *zwriteline;
    345347} owl_message;
     348
     349#define OWL_FMTEXT_CACHE_SIZE 1000
     350/* We cache the saved fmtexts for the last bunch of messages we
     351   rendered */
     352typedef struct _owl_fmtext_cache {
     353    owl_message * message;
     354    owl_fmtext fmtext;
     355} owl_fmtext_cache;
    346356
    347357typedef struct _owl_style {
Note: See TracChangeset for help on using the changeset viewer.