]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
read() less often
authorTimo Sirainen <tss@iki.fi>
Sat, 19 Jun 2004 22:06:52 +0000 (01:06 +0300)
committerTimo Sirainen <tss@iki.fi>
Sat, 19 Jun 2004 22:06:52 +0000 (01:06 +0300)
--HG--
branch : HEAD

src/lib-storage/index/mbox/istream-raw-mbox.c

index e3b8f2689ec8a8bb9fb0c8da77beadedf38b8371..69ca936839b963dfd065ce9c1718c998f6795a3f 100644 (file)
@@ -148,33 +148,38 @@ static ssize_t _read(struct _istream *stream)
        stream->skip = 0;
        stream->buffer = NULL;
 
+       ret = 0;
        do {
-               ret = i_stream_read(rstream->input);
                buf = i_stream_get_data(rstream->input, &pos);
-       } while (ret > 0 && (pos == 1 ||
-                            stream->istream.v_offset + pos <=
-                            rstream->input_peak_offset));
+               if (pos > 1 &&
+                   stream->istream.v_offset + pos > rstream->input_peak_offset)
+                       break;
+               ret = i_stream_read(rstream->input);
+       } while (ret > 0);
 
        if (ret < 0) {
-               if (ret == -2)
-                       return -2;
-
-               /* we've read the whole file, final byte should be
-                  the \n trailer */
-               if (pos > 0 && buf[pos-1] == '\n')
-                       pos--;
+               if (ret == -2) {
+                       if (stream->istream.v_offset + pos ==
+                           rstream->input_peak_offset)
+                               return -2;
+               } else {
+                       /* we've read the whole file, final byte should be
+                          the \n trailer */
+                       if (pos > 0 && buf[pos-1] == '\n')
+                               pos--;
 
-               i_assert(pos >= stream->pos);
-               ret = pos == stream->pos ? -1 :
-                       (ssize_t)(pos - stream->pos);
+                       i_assert(pos >= stream->pos);
+                       ret = pos == stream->pos ? -1 :
+                               (ssize_t)(pos - stream->pos);
 
-               stream->buffer = buf;
-               stream->pos = pos;
+                       stream->buffer = buf;
+                       stream->pos = pos;
 
-               rstream->eom = TRUE;
-               rstream->eof = TRUE;
-               handle_end_of_mail(rstream, pos);
-               return ret < 0 ? _read(stream) : ret;
+                       rstream->eom = TRUE;
+                       rstream->eof = TRUE;
+                       handle_end_of_mail(rstream, pos);
+                       return ret < 0 ? _read(stream) : ret;
+               }
        }
 
        if (stream->istream.v_offset == rstream->from_offset) {