]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Improve the performance of the uudecode bidder when reading a very long line.
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Thu, 28 Jul 2011 03:58:35 +0000 (23:58 -0400)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Thu, 28 Jul 2011 03:58:35 +0000 (23:58 -0400)
SVN-Revision: 3507

libarchive/archive_read_support_filter_uu.c

index fac7a10cb5540d8aa0ecbce70e8a3d715cabc5c2..56fb6623d17474e4bc60b3376cd771cc20e87d46 100644 (file)
@@ -220,17 +220,26 @@ bid_get_line(struct archive_read_filter *filter,
                len = 0;
        } else
                len = get_line(*b, *avail, nl);
+
        /*
         * Read bytes more while it does not reach the end of line.
         */
-       while (*nl == 0 && len == *avail && !quit && *nbytes_read < UUENCODE_BID_MAX_READ) {
+       while (*nl == 0 && len == *avail && !quit &&
+           *nbytes_read < UUENCODE_BID_MAX_READ) {
                ssize_t diff = *ravail - *avail;
+               size_t nbytes_req = (*ravail+1023) & ~1023U;
+               ssize_t tested;
+
+               /* Increase reading bytes if it is not enough to at least
+                * new two lines. */
+               if (nbytes_req < (size_t)*ravail + 160)
+                       nbytes_req <<= 1;
 
-               *b = __archive_read_filter_ahead(filter, 160 + *ravail, avail);
+               *b = __archive_read_filter_ahead(filter, nbytes_req, avail);
                if (*b == NULL) {
                        if (*ravail >= *avail)
                                return (0);
-                       /* Reading bytes reaches the end of file. */
+                       /* Reading bytes reaches the end of a stream. */
                        *b = __archive_read_filter_ahead(filter, *avail, avail);
                        quit = 1;
                }
@@ -238,7 +247,10 @@ bid_get_line(struct archive_read_filter *filter,
                *ravail = *avail;
                *b += diff;
                *avail -= diff;
-               len = get_line(*b, *avail, nl);
+               tested = len;/* Skip some bytes we already determinated. */
+               len = get_line(*b + tested, *avail - tested, nl);
+               if (len >= 0)
+                       len += tested;
        }
        return (len);
 }