]> granicus.if.org Git - neomutt/commitdiff
A couple of optimizations, most notably for the special case of a
authorThomas Roessler <roessler@does-not-exist.org>
Wed, 31 Mar 1999 00:11:03 +0000 (00:11 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Wed, 31 Mar 1999 00:11:03 +0000 (00:11 +0000)
non-prefix state.

charset.c
charset.h
handler.c

index b2ff695c437995fc3a1f1410b26a926a4cd744aa..c19619f6d3fe9d9e1f20768f7a2bdfc25a635345 100644 (file)
--- a/charset.c
+++ b/charset.c
@@ -909,19 +909,43 @@ static void _process_data (DECODER *, short);
 
 void mutt_decoder_push (DECODER *d, void *_buff, size_t blen, size_t *taken)
 {
+  struct decoder_buff *b;
+  
   if (!_buff || !blen)
   {
     _process_data (d, 1);
     return;
   }
-
-  if ((*taken = MIN(blen, d->in.size - d->in.used)))
+  
+  /* shortcut the identity mapping and save one copying pass */
+  
+  if (d->just_take_id)
+    b = &d->out;
+  else
+    b = &d->in;
+    
+  if ((*taken = MIN(blen, b->size - b->used)))
   {
-    memcpy (d->in.buff + d->in.used, _buff, *taken);
-    d->in.used += *taken;
+    memcpy (b->buff + b->used, _buff, *taken);
+    b->used += *taken;
   }
 }
 
+int mutt_decoder_push_one (DECODER *d, char c)
+{
+  struct decoder_buff *b;
+
+  if (d->just_take_id)
+    b = &d->out;
+  else
+    b = &d->in;
+
+  if (b->used == b->size)
+    return -1;
+  
+  b->buff[b->used++] = c;
+  return 0;
+}
 
 void mutt_decoder_pop (DECODER *d, void *_buff, size_t blen, size_t *popped)
 {
@@ -941,14 +965,26 @@ void mutt_decoder_pop_to_state (DECODER *d, STATE *s)
 {
   char tmp[DECODER_BUFFSIZE];
   size_t i, l;
-  
-  do 
+
+  if (s->prefix)
+  {
+    do 
+    {
+      mutt_decoder_pop (d, tmp, sizeof (tmp), &l);
+      for (i = 0; i < l; i++)
+       state_prefix_putc (tmp[i], s);
+    }
+    while (l > 0);
+  }
+  else
   {
-    mutt_decoder_pop (d, tmp, sizeof (tmp), &l);
-    for (i = 0; i < l; i++)
-      state_prefix_putc (tmp[i], s);
+    do 
+    {
+      mutt_decoder_pop (d, tmp, sizeof (tmp), &l);
+      fwrite (tmp, l, 1, s->fpout);
+    }
+    while (l > 0);
   }
-  while (l > 0);
 }
 
 /* this is where things actually happen */
@@ -1010,18 +1046,13 @@ static void _process_data (DECODER *d, short force)
 {
   if (force) d->forced = 1;
   
-  if (d->just_take_id)
+  if (!d->just_take_id)
   {
-    size_t l = MIN (d->out.size - d->out.used, d->in.used);
-    memmove (d->out.buff + d->out.used, d->in.buff, l);
-    memmove (d->in.buff, d->in.buff + l, d->in.used - l);
-    d->in.used -= l;
-    d->out.used += l;
+    if (d->src_is_utf8)
+      _process_data_utf8 (d);
+    else
+      _process_data_8bit (d);
   }
-  else if (d->src_is_utf8)
-    _process_data_utf8 (d);
-  else
-    _process_data_8bit (d);
 }
 
 /* This one is currently lacking utf-8 support */
index 8f466ef5a432b44f243cc5b00b4a733a04797841..a3d444ee7ebd99e37d6e6de7a7f9b134e07d7c5a 100644 (file)
--- a/charset.h
+++ b/charset.h
@@ -84,6 +84,7 @@ void mutt_decoder_push (DECODER *, void *, size_t, size_t *);
 void mutt_decoder_pop (DECODER *, void *, size_t, size_t *);
 void mutt_decoder_pop_to_state (DECODER *, STATE *);
 void mutt_free_decoder (DECODER **);
+int mutt_decoder_push_one (DECODER *, char);
 
 CHARSET *mutt_get_charset(const char *);
 CHARSET_MAP *mutt_get_translation(const char *, const char *);
index 66c15df9dd03cdc469b3560a47cdf9d248a8a78b..f9cce3d82b7e84ff27f42ad6cdd8ada109e0eb8d 100644 (file)
--- a/handler.c
+++ b/handler.c
@@ -68,8 +68,7 @@ void mutt_decode_xbit (STATE *s, BODY *b, int istext, DECODER *dec)
 {
   long len = b->length;
   int c, ch;
-  char cc;
-  size_t l;
+  int l = 0;
 
   if (istext)
   {
@@ -88,12 +87,14 @@ void mutt_decode_xbit (STATE *s, BODY *b, int istext, DECODER *dec)
          ungetc(ch, s->fpin);
       }
 
-      cc = c;
-      mutt_decoder_push (dec, &cc, 1, &l);
-      mutt_decoder_pop_to_state (dec, s);
-      
+      mutt_decoder_push_one (dec, c);
+      if (l++ == 1024)
+      {
+       mutt_decoder_pop_to_state (dec, s);
+       l = 0;
+      }
     }
-    
+
     mutt_decoder_push (dec, NULL, 0, NULL);
     mutt_decoder_pop_to_state (dec, s);
 
@@ -119,8 +120,7 @@ void mutt_decode_quoted (STATE *s, BODY *b, int istext, DECODER *dec)
 {
   long len = b->length;
   int ch;
-  char cc;
-  size_t l;
+  int l = 0;
 
   state_set_prefix(s);
 
@@ -179,9 +179,12 @@ void mutt_decode_quoted (STATE *s, BODY *b, int istext, DECODER *dec)
 
     if(ch != EOF)
     {
-      cc = ch;
-      mutt_decoder_push (dec, &cc, 1, &l);
-      mutt_decoder_pop_to_state (dec, s);
+      mutt_decoder_push_one (dec, ch);
+      if (l++ == 1024)
+      {
+       mutt_decoder_pop_to_state (dec, s);
+       l = 0;
+      }
     }
   }
 
@@ -196,8 +199,7 @@ void mutt_decode_base64 (STATE *s, BODY *b, int istext, DECODER *dec)
   long len = b->length;
   char buf[5];
   int c1, c2, c3, c4, ch, cr = 0, i;
-  char cc;
-  size_t l;
+  size_t l = 0;
 
   buf[4] = 0;
 
@@ -221,8 +223,7 @@ void mutt_decode_base64 (STATE *s, BODY *b, int istext, DECODER *dec)
 
     if (cr && ch != '\n') 
     {
-      cc = '\r';
-      mutt_decoder_push (dec, &cc, 1, &l);
+      mutt_decoder_push_one (dec, '\r');
     }
     cr = 0;
       
@@ -230,8 +231,7 @@ void mutt_decode_base64 (STATE *s, BODY *b, int istext, DECODER *dec)
       cr = 1;
     else
     {
-      cc = ch;
-      mutt_decoder_push (dec, &cc, 1, &l);
+      mutt_decoder_push_one (dec, ch);
     }
 
     if (buf[2] == '=')
@@ -241,8 +241,7 @@ void mutt_decode_base64 (STATE *s, BODY *b, int istext, DECODER *dec)
 
     if (cr && ch != '\n')
     {
-      cc = ch;
-      mutt_decoder_push (dec, &cc, 1, &l);
+      mutt_decoder_push_one (dec, ch);
     }
 
     cr = 0;
@@ -251,8 +250,7 @@ void mutt_decode_base64 (STATE *s, BODY *b, int istext, DECODER *dec)
       cr = 1;
     else
     {
-      cc = ch;
-      mutt_decoder_push (dec, &cc, 1, &l);
+      mutt_decoder_push_one (dec, ch);
     }
 
     if (buf[3] == '=') break;
@@ -261,8 +259,7 @@ void mutt_decode_base64 (STATE *s, BODY *b, int istext, DECODER *dec)
 
     if (cr && ch != '\n')
     {
-      cc = ch;
-      mutt_decoder_push (dec, &cc, 1, &l);
+      mutt_decoder_push_one (dec, ch);
     }
     cr = 0;
 
@@ -270,11 +267,14 @@ void mutt_decode_base64 (STATE *s, BODY *b, int istext, DECODER *dec)
       cr = 1;
     else
     {
-      cc = ch;
-      mutt_decoder_push (dec, &cc, 1, &l);
+      mutt_decoder_push_one (dec, ch);
     }
     
-    mutt_decoder_pop_to_state (dec, s);
+    if ((l += 3) >= 1024)
+    {
+      mutt_decoder_pop_to_state (dec, s);
+      l = 0;
+    }
   }
   mutt_decoder_push (dec, NULL, 0, NULL);
   mutt_decoder_pop_to_state (dec, s);
@@ -295,8 +295,7 @@ void mutt_decode_uuencoded (STATE *s, BODY *b, int istext, DECODER *dec)
   char linelen, c, l, out;
   char *pt;
   long len = b->length;
-  size_t dummy;
-  
+
   if(istext)
     state_set_prefix(s);
   
@@ -325,7 +324,7 @@ void mutt_decode_uuencoded (STATE *s, BODY *b, int istext, DECODER *dec)
        out = decode_byte (*pt) << l;
        pt++;
        out |= (decode_byte (*pt) >> (6 - l));
-       mutt_decoder_push (dec, &out, 1, &dummy);
+       mutt_decoder_push_one (dec, out);
        c++;
        if (c == linelen)
          break;