From 7503518bac267252307ac30802aeea9ff47ba80f Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 12 Apr 2008 04:14:55 +0000 Subject: added inline function successor() The new function successor() can be used to simplify a lot of code lines and saves a lot of "i+>=buffered_chunks" checks. git-svn-id: https://svn.musicpd.org/mpd/trunk@7285 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/outputBuffer.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/outputBuffer.c b/src/outputBuffer.c index 9e97c3dff..26dc50a91 100644 --- a/src/outputBuffer.c +++ b/src/outputBuffer.c @@ -39,13 +39,19 @@ void clearOutputBuffer(OutputBuffer * cb) cb->currentChunk = -1; } +/** return the index of the chunk after i */ +static inline unsigned successor(unsigned i) +{ + assert(i <= buffered_chunks); + + ++i; + return i == buffered_chunks ? 0 : i; +} + void flushOutputBuffer(OutputBuffer * cb) { if (cb->currentChunk == cb->end) { - if (((unsigned)cb->end + 1) >= buffered_chunks) { - cb->end = 0; - } - else cb->end++; + cb->end = successor(cb->end); cb->currentChunk = -1; } } @@ -60,9 +66,7 @@ void outputBufferShift(OutputBuffer * cb) assert(cb->begin != cb->end); assert(cb->begin < buffered_chunks); - ++cb->begin; - if (cb->begin >= buffered_chunks) - cb->begin = 0; + cb->begin = successor(cb->begin); } unsigned int outputBufferRelative(const OutputBuffer * cb, unsigned i) @@ -121,10 +125,7 @@ static int tailChunk(OutputBuffer * cb, InputStream * inStream, if (cb->currentChunk == cb->end) return cb->currentChunk; - next = cb->end + 1; - if (next >= buffered_chunks) { - next = 0; - } + next = successor(cb->end); while (cb->begin == next && !dc->stop) { if (dc->seek) { if (seekable) { -- cgit v1.2.3