From e2efb20bc5b91a7c9e9d3467aeb4aadc73a7bc91 Mon Sep 17 00:00:00 2001 From: Mathis Rosenhauer Date: Thu, 6 Dec 2012 10:55:40 +0100 Subject: [PATCH] killed loop + other simplifications --- src/encode.c | 33 +++++++++++++++------------------ src/encode.h | 1 + 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/encode.c b/src/encode.c index 4b4f237..64f5f3f 100644 --- a/src/encode.c +++ b/src/encode.c @@ -463,16 +463,18 @@ static int m_flush_block_resumable(struct aec_stream *strm) */ struct internal_state *state = strm->state; - while(state->cds_buf + state->i < state->cds) { - if (strm->avail_out == 0) - return M_EXIT; - - *strm->next_out++ = state->cds_buf[state->i]; - strm->avail_out--; - state->i++; + int n = MIN(state->cds - state->cds_buf - state->i, strm->avail_out); + memcpy(strm->next_out, state->cds_buf + state->i, n); + strm->next_out += n; + strm->avail_out -= n; + state->i += n; + + if (strm->avail_out == 0) { + return M_EXIT; + } else { + state->mode = m_get_block; + return M_CONTINUE; } - state->mode = m_get_block; - return M_CONTINUE; } static int m_flush_block(struct aec_stream *strm) @@ -654,7 +656,6 @@ static int m_get_rsi_resumable(struct aec_stream *strm) to full RSI. */ - int j; struct internal_state *state = strm->state; do { @@ -663,15 +664,11 @@ static int m_get_rsi_resumable(struct aec_stream *strm) } else { if (state->flush == AEC_FLUSH) { if (state->i > 0) { - for (j = state->i; j < strm->rsi * strm->block_size; j++) - state->data_raw[j] = state->data_raw[state->i - 1]; - state->i = strm->rsi * strm->block_size; + do + state->data_raw[state->i] = + state->data_raw[state->i - 1]; + while(++state->i < strm->rsi * strm->block_size); } else { - if (state->zero_blocks) { - state->mode = m_encode_zero; - return M_CONTINUE; - } - emit(state, 0, state->bits); if (strm->avail_out > 0) { if (!state->direct_out) diff --git a/src/encode.h b/src/encode.h index 8bcf6db..2510c10 100644 --- a/src/encode.h +++ b/src/encode.h @@ -64,6 +64,7 @@ #define M_CONTINUE 1 #define M_EXIT 0 +#define MIN(a, b) (((a) < (b))? (a): (b)) struct internal_state { int (*mode)(struct aec_stream *); -- 2.7.4