Changeset a387d12e for fmtext.c


Ignore:
Timestamp:
Mar 27, 2007, 10:04:10 PM (14 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, barnowl_perlaim, debian, 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.
File:
1 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);
Note: See TracChangeset for help on using the changeset viewer.