From: Michihiro NAKAJIMA Date: Thu, 28 Jul 2011 03:58:35 +0000 (-0400) Subject: Improve the performance of the uudecode bidder when reading a very long line. X-Git-Tag: v3.0.0a~224 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2d3cd81cde45645941aaa450d2ac40262bd211fc;p=thirdparty%2Flibarchive.git Improve the performance of the uudecode bidder when reading a very long line. SVN-Revision: 3507 --- diff --git a/libarchive/archive_read_support_filter_uu.c b/libarchive/archive_read_support_filter_uu.c index fac7a10cb..56fb6623d 100644 --- a/libarchive/archive_read_support_filter_uu.c +++ b/libarchive/archive_read_support_filter_uu.c @@ -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); }