diff options
author | wm4 <wm4@nowhere> | 2019-11-07 14:53:19 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2019-11-07 22:53:13 +0100 |
commit | f850d82e656a9add1bd286f901f18c5213580606 (patch) | |
tree | 97fe2b74ea85f81bdb2791d676d9ba095aa576c2 /stream/stream.c | |
parent | 53f17a71f4bd33fdc2fc08b72138f477e8e02639 (diff) | |
download | mpv-f850d82e656a9add1bd286f901f18c5213580606.tar.bz2 mpv-f850d82e656a9add1bd286f901f18c5213580606.tar.xz |
stream: avoid a duplicate condition
stream_read_peek() duplicated what stream_read_more() checks for anyway
(whether the forward buffer is large enough). This can be skipped by
making the stream_read_more() return value more consistent.
Diffstat (limited to 'stream/stream.c')
-rw-r--r-- | stream/stream.c | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/stream/stream.c b/stream/stream.c index fdaecf9ec8..504d217b46 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -470,14 +470,14 @@ static int stream_read_unbuffered(stream_t *s, void *buf, int len) // Ask for having at most "forward" bytes ready to read in the buffer. // To read everything, you may have to call this in a loop. // forward: desired amount of bytes in buffer after s->cur_pos -// returns: progress (false on EOF or memory allocation failure) +// returns: progress (false on EOF or on OOM or if enough data was available) static bool stream_read_more(struct stream *s, int forward) { assert(forward >= 0); int forward_avail = s->buf_end - s->buf_cur; if (forward_avail >= forward) - return true; + return false; // Avoid that many small reads will lead to many low-level read calls. forward = MPMAX(forward, s->requested_buffer_size / 2); @@ -580,10 +580,7 @@ int stream_read(stream_t *s, char *mem, int total) // the buffer to satisfy the read request. int stream_read_peek(stream_t *s, void* buf, int buf_size) { - while (s->buf_end - s->buf_cur < buf_size) { - if (!stream_read_more(s, buf_size)) - break; - } + while (stream_read_more(s, buf_size)) {} return ring_copy(s, buf, buf_size, s->buf_cur); } |