bzip2: more of code shrink
compressStream 503 473 -30 BZ2_bzCompress 78 - -78 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 0/1 up/down: 0/-108) Total: -108 bytes text data bss dec hex filename 676300 2538 12104 690942 a8afe busybox_old 676192 2538 12104 690834 a8a92 busybox_unstripped
This commit is contained in:
parent
16e74b7464
commit
31acd1ba0a
@ -76,11 +76,9 @@ void init_RL(EState* s)
|
|||||||
|
|
||||||
|
|
||||||
static
|
static
|
||||||
Bool isempty_RL(EState* s)
|
int isempty_RL(EState* s)
|
||||||
{
|
{
|
||||||
if (s->state_in_ch < 256 && s->state_in_len > 0)
|
return (s->state_in_ch >= 256 || s->state_in_len <= 0);
|
||||||
return False;
|
|
||||||
return True;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -333,7 +331,7 @@ int BZ2_bzCompress(bz_stream *strm, int action)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef FLUSH_IS_UNUSED
|
#ifdef FLUSH_IS_UNUSED
|
||||||
case_BZ_M_FLUSHING:
|
case_BZ_M_FLUSHING:
|
||||||
case BZ_M_FLUSHING:
|
case BZ_M_FLUSHING:
|
||||||
/*if (s->avail_in_expect != s->strm->avail_in)
|
/*if (s->avail_in_expect != s->strm->avail_in)
|
||||||
return BZ_SEQUENCE_ERROR;*/
|
return BZ_SEQUENCE_ERROR;*/
|
||||||
|
@ -51,79 +51,55 @@ enum {
|
|||||||
IOBUF_SIZE = 8 * 1024
|
IOBUF_SIZE = 8 * 1024
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static uint8_t level;
|
||||||
|
|
||||||
|
/* NB: compressStream() has to return -1 on errors, not die.
|
||||||
|
* bbunpack() will correctly clean up in this case
|
||||||
|
* (delete incomplete .bz2 file)
|
||||||
|
*/
|
||||||
|
|
||||||
/* Returns:
|
/* Returns:
|
||||||
* <0 on write errors (examine errno),
|
* -1 on errors
|
||||||
* >0 on short writes (errno == 0)
|
* total written bytes so far otherwise
|
||||||
* 0 no error (entire input consumed, gimme more)
|
|
||||||
* on "impossible" errors (internal bzip2 compressor bug) dies
|
|
||||||
*/
|
*/
|
||||||
static
|
static
|
||||||
ssize_t bz_write(bz_stream *strm, void* rbuf, ssize_t rlen, void *wbuf)
|
USE_DESKTOP(long long) int bz_write(bz_stream *strm, void* rbuf, ssize_t rlen, void *wbuf)
|
||||||
{
|
{
|
||||||
int n, n2, ret;
|
int n, n2, ret;
|
||||||
|
|
||||||
strm->avail_in = rlen;
|
strm->avail_in = rlen;
|
||||||
strm->next_in = rbuf;
|
strm->next_in = rbuf;
|
||||||
while (1) {
|
while (1) {
|
||||||
strm->avail_out = IOBUF_SIZE;
|
strm->avail_out = IOBUF_SIZE;
|
||||||
strm->next_out = wbuf;
|
strm->next_out = wbuf;
|
||||||
|
|
||||||
ret = BZ2_bzCompress(strm, BZ_RUN);
|
ret = BZ2_bzCompress(strm, rlen ? BZ_RUN : BZ_FINISH);
|
||||||
if (ret != BZ_RUN_OK)
|
if (ret != BZ_RUN_OK /* BZ_RUNning */
|
||||||
|
&& ret != BZ_FINISH_OK /* BZ_FINISHing, but not done yet */
|
||||||
|
&& ret != BZ_STREAM_END /* BZ_FINISHed */
|
||||||
|
) {
|
||||||
bb_error_msg_and_die("internal error %d", ret);
|
bb_error_msg_and_die("internal error %d", ret);
|
||||||
|
|
||||||
n = IOBUF_SIZE - strm->avail_out;
|
|
||||||
if (n) {
|
|
||||||
/* short reads must have errno == 0 */
|
|
||||||
errno = 0;
|
|
||||||
n2 = full_write(STDOUT_FILENO, wbuf, n);
|
|
||||||
if (n2 != n)
|
|
||||||
return n2 ? n2 : 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strm->avail_in == 0)
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------*/
|
|
||||||
static
|
|
||||||
USE_DESKTOP(long long) int bz_write_tail(bz_stream *strm, void *wbuf)
|
|
||||||
{
|
|
||||||
int n, n2, ret;
|
|
||||||
USE_DESKTOP(long long) int total;
|
|
||||||
|
|
||||||
total = -1;
|
|
||||||
while (1) {
|
|
||||||
strm->avail_out = IOBUF_SIZE;
|
|
||||||
strm->next_out = wbuf;
|
|
||||||
|
|
||||||
ret = BZ2_bzCompress(strm, BZ_FINISH);
|
|
||||||
if (ret != BZ_FINISH_OK && ret != BZ_STREAM_END)
|
|
||||||
bb_error_msg_and_die("internal error %d", ret);
|
|
||||||
|
|
||||||
n = IOBUF_SIZE - strm->avail_out;
|
n = IOBUF_SIZE - strm->avail_out;
|
||||||
if (n) {
|
if (n) {
|
||||||
n2 = full_write(STDOUT_FILENO, wbuf, n);
|
n2 = full_write(STDOUT_FILENO, wbuf, n);
|
||||||
if (n2 != n)
|
if (n2 != n) {
|
||||||
goto err;
|
if (n2 >= 0)
|
||||||
|
errno = 0; /* prevent bogus error message */
|
||||||
|
bb_perror_msg(n2 >= 0 ? "short write" : "write error");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret == BZ_STREAM_END)
|
if (ret == BZ_STREAM_END)
|
||||||
break;
|
break;
|
||||||
|
if (rlen && strm->avail_in == 0)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
return 0 USE_DESKTOP( + strm->total_out );
|
||||||
total = 0 USE_DESKTOP( + strm->total_out );
|
|
||||||
err:
|
|
||||||
#if ENABLE_FEATURE_CLEAN_UP
|
|
||||||
BZ2_bzCompressEnd(strm);
|
|
||||||
#endif
|
|
||||||
return total;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t level;
|
|
||||||
|
|
||||||
static
|
static
|
||||||
USE_DESKTOP(long long) int compressStream(void)
|
USE_DESKTOP(long long) int compressStream(void)
|
||||||
{
|
{
|
||||||
@ -136,26 +112,26 @@ USE_DESKTOP(long long) int compressStream(void)
|
|||||||
#define wbuf (iobuf + IOBUF_SIZE)
|
#define wbuf (iobuf + IOBUF_SIZE)
|
||||||
|
|
||||||
iobuf = xmalloc(2 * IOBUF_SIZE);
|
iobuf = xmalloc(2 * IOBUF_SIZE);
|
||||||
|
|
||||||
BZ2_bzCompressInit(strm, level);
|
BZ2_bzCompressInit(strm, level);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
count = full_read(STDIN_FILENO, rbuf, IOBUF_SIZE);
|
count = full_read(STDIN_FILENO, rbuf, IOBUF_SIZE);
|
||||||
if (count < 0)
|
if (count < 0) {
|
||||||
bb_perror_msg("read error");
|
bb_perror_msg("read error");
|
||||||
if (count <= 0)
|
total = -1;
|
||||||
break;
|
|
||||||
count = bz_write(strm, rbuf, count, wbuf);
|
|
||||||
if (count) {
|
|
||||||
bb_perror_msg(count < 0 ? "write error" : "short write");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
/* if count == 0, bz_write finalizes compression */
|
||||||
|
total = bz_write(strm, rbuf, count, wbuf);
|
||||||
|
if (count == 0 || total < 0)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
total = bz_write_tail(strm, wbuf);
|
#if ENABLE_FEATURE_CLEAN_UP
|
||||||
|
BZ2_bzCompressEnd(strm);
|
||||||
free(iobuf);
|
free(iobuf);
|
||||||
/* we had no error _only_ if count == 0 */
|
#endif
|
||||||
return count == 0 ? total : -1;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
|
Loading…
Reference in New Issue
Block a user