Skip to content

Commit

Permalink
lib: istream-chain/concat cleanup - return early if no new data is read
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sirainen authored and Timo Sirainen committed Nov 1, 2017
1 parent fdf15b2 commit 59a6379
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
14 changes: 7 additions & 7 deletions src/lib/istream-chain.c
Expand Up @@ -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. */
Expand All @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions src/lib/istream-concat.c
Expand Up @@ -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. */
Expand All @@ -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;
Expand Down

0 comments on commit 59a6379

Please sign in to comment.