]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
istream_next_line() optimization.
authorTimo Sirainen <tss@iki.fi>
Wed, 1 Sep 2010 15:22:00 +0000 (16:22 +0100)
committerTimo Sirainen <tss@iki.fi>
Wed, 1 Sep 2010 15:22:00 +0000 (16:22 +0100)
Based on patch by Len7hir

src/lib/istream.c

index f20dfe4b0fef400da80eb868a6e56f301b108dd7..982eb69b3defd7f61d1d3f0c5fe24973d309dc27 100644 (file)
@@ -336,8 +336,7 @@ static char *i_stream_last_line(struct istream_private *_stream)
 char *i_stream_next_line(struct istream *stream)
 {
        struct istream_private *_stream = stream->real_stream;
-       char *ret_buf;
-        size_t i;
+       const unsigned char *pos;
 
        if (_stream->skip >= _stream->pos) {
                stream->stream_errno = 0;
@@ -350,18 +349,14 @@ char *i_stream_next_line(struct istream *stream)
                return NULL;
        }
 
-       /* @UNSAFE */
-       ret_buf = NULL;
-       for (i = _stream->skip; i < _stream->pos; i++) {
-               if (_stream->buffer[i] == 10) {
-                       /* got it */
-                       ret_buf = i_stream_next_line_finish(_stream, i);
-                        break;
-               }
-       }
-       if (ret_buf == NULL)
+       pos = memchr(_stream->buffer + _stream->skip, '\n',
+                    _stream->pos - _stream->skip);
+       if (pos == NULL) {
+               return i_stream_next_line_finish(_stream,
+                                                pos - _stream->buffer);
+       } else {
                return i_stream_last_line(_stream);
-        return ret_buf;
+       }
 }
 
 char *i_stream_read_next_line(struct istream *stream)