From: Timo Sirainen Date: Thu, 26 Oct 2017 11:56:26 +0000 (+0300) Subject: lib: istream-chain/concat cleanup - return early if no new data is read X-Git-Tag: 2.3.0.rc1~653 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=59a63791d4ec70a134cb0dcbad1255d952075efe;p=thirdparty%2Fdovecot%2Fcore.git lib: istream-chain/concat cleanup - return early if no new data is read There's no need to change the buffer or other variables. This simplifies the following changes. This cleanup is identical for istream-concat and istream-chain. --- diff --git a/src/lib/istream-chain.c b/src/lib/istream-chain.c index fbe458a2a6..d192204c5e 100644 --- a/src/lib/istream-chain.c +++ b/src/lib/istream-chain.c @@ -243,17 +243,17 @@ static ssize_t i_stream_chain_read(struct istream_private *stream) data = i_stream_get_data(link->stream, &data_size); } + if (data_size == cur_data_pos) { + /* nothing new read - preserve the buffer as it was */ + i_assert(ret == 0 || ret == -1); + return ret; + } if (cstream->prev_stream_left == 0) { /* we can point directly to the current stream's buffers */ stream->buffer = data; stream->pos -= stream->skip; stream->skip = 0; new_pos = data_size; - } else if (data_size == cur_data_pos) { - /* nothing new read */ - i_assert(ret == 0 || ret == -1); - stream->buffer = stream->w_buffer; - new_pos = stream->pos; } else { /* we still have some of the previous stream left. merge the new data with it. */ @@ -265,8 +265,8 @@ static ssize_t i_stream_chain_read(struct istream_private *stream) new_pos = stream->pos + new_bytes_count; } - ret = new_pos > stream->pos ? (ssize_t)(new_pos - stream->pos) : - (ret == 0 ? 0 : -1); + i_assert(new_pos > stream->pos); + ret = (ssize_t)(new_pos - stream->pos); stream->pos = new_pos; cstream->prev_skip = stream->skip; return ret; diff --git a/src/lib/istream-concat.c b/src/lib/istream-concat.c index 2f5efd2971..29ecfdd8a7 100644 --- a/src/lib/istream-concat.c +++ b/src/lib/istream-concat.c @@ -187,17 +187,17 @@ static ssize_t i_stream_concat_read(struct istream_private *stream) data = i_stream_get_data(cstream->cur_input, &data_size); } + if (data_size == cur_data_pos) { + /* nothing new read - preserve the buffer as it was */ + i_assert(ret == 0 || ret == -1); + return ret; + } if (cstream->prev_stream_left == 0) { /* we can point directly to the current stream's buffers */ stream->buffer = data; stream->pos -= stream->skip; stream->skip = 0; new_pos = data_size; - } else if (data_size == cur_data_pos) { - /* nothing new read */ - i_assert(ret == 0 || ret == -1); - stream->buffer = stream->w_buffer; - new_pos = stream->pos; } else { /* we still have some of the previous stream left. merge the new data with it. */ @@ -219,8 +219,8 @@ static ssize_t i_stream_concat_read(struct istream_private *stream) new_pos = stream->pos + new_bytes_count; } - ret = new_pos > stream->pos ? (ssize_t)(new_pos - stream->pos) : - (ret == 0 ? 0 : -1); + i_assert(new_pos > stream->pos); + ret = (ssize_t)(new_pos - stream->pos); stream->pos = new_pos; cstream->prev_skip = stream->skip; return ret;