]> granicus.if.org Git - mutt/commitdiff
Another small charset optimization.
authorThomas Roessler <roessler@does-not-exist.org>
Wed, 31 Mar 1999 06:34:01 +0000 (06:34 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Wed, 31 Mar 1999 06:34:01 +0000 (06:34 +0000)
charset.c
charset.h

index c19619f6d3fe9d9e1f20768f7a2bdfc25a635345..3a6fad546e4bc1db8bdee169285fb19cdeb10885 100644 (file)
--- a/charset.c
+++ b/charset.c
@@ -876,9 +876,12 @@ DECODER *mutt_open_decoder (const char *src, const char *dest)
   d->in.size = DECODER_BUFFSIZE;
   d->out.size = DECODER_BUFFSIZE;
 
+  d->_in = &d->out;
+  
   if (!src || !dest || mutt_is_utf8 (dest))
   {
     d->just_take_id = 1;
+    d->_in = &d->in;
     return d;
   }
   
@@ -887,6 +890,7 @@ DECODER *mutt_open_decoder (const char *src, const char *dest)
     if (!(d->chs = mutt_get_charset (dest)) || unicode_init () == -1)
     {
       d->just_take_id = 1;
+      d->_in = &d->in;
       return d;
     }
     
@@ -895,8 +899,11 @@ DECODER *mutt_open_decoder (const char *src, const char *dest)
   }
   
   if (!(d->chm = mutt_get_translation (src, dest)))
+  {
     d->just_take_id = 1;
-  
+    d->_in = &d->in;
+  }
+
   return d;
 }
 
@@ -909,41 +916,25 @@ 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;
   }
-  
-  /* 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)))
+
+  if ((*taken = MIN(blen, d->_in->size - d->_in->used)))
   {
-    memcpy (b->buff + b->used, _buff, *taken);
-    b->used += *taken;
+    memcpy (d->_in->buff + d->_in->used, _buff, *taken);
+    d->_in->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)
+  if (d->_in->used == d->_in->size)
     return -1;
-  
-  b->buff[b->used++] = c;
+
+  d->_in->buff[d->_in->used++] = c;
   return 0;
 }
 
index a3d444ee7ebd99e37d6e6de7a7f9b134e07d7c5a..cf72a853db59d2d17e653ee90e18d1c7ff960497 100644 (file)
--- a/charset.h
+++ b/charset.h
@@ -76,6 +76,7 @@ typedef struct decoder
   /* the buffers */
   struct decoder_buff in;
   struct decoder_buff out;
+  struct decoder_buff *_in;
 } 
 DECODER;