Commit 7503518b authored by Max Kellermann's avatar Max Kellermann Committed by Eric Wong

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
parent 079f13bc
...@@ -39,13 +39,19 @@ void clearOutputBuffer(OutputBuffer * cb) ...@@ -39,13 +39,19 @@ void clearOutputBuffer(OutputBuffer * cb)
cb->currentChunk = -1; 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) void flushOutputBuffer(OutputBuffer * cb)
{ {
if (cb->currentChunk == cb->end) { if (cb->currentChunk == cb->end) {
if (((unsigned)cb->end + 1) >= buffered_chunks) { cb->end = successor(cb->end);
cb->end = 0;
}
else cb->end++;
cb->currentChunk = -1; cb->currentChunk = -1;
} }
} }
...@@ -60,9 +66,7 @@ void outputBufferShift(OutputBuffer * cb) ...@@ -60,9 +66,7 @@ void outputBufferShift(OutputBuffer * cb)
assert(cb->begin != cb->end); assert(cb->begin != cb->end);
assert(cb->begin < buffered_chunks); assert(cb->begin < buffered_chunks);
++cb->begin; cb->begin = successor(cb->begin);
if (cb->begin >= buffered_chunks)
cb->begin = 0;
} }
unsigned int outputBufferRelative(const OutputBuffer * cb, unsigned i) unsigned int outputBufferRelative(const OutputBuffer * cb, unsigned i)
...@@ -121,10 +125,7 @@ static int tailChunk(OutputBuffer * cb, InputStream * inStream, ...@@ -121,10 +125,7 @@ static int tailChunk(OutputBuffer * cb, InputStream * inStream,
if (cb->currentChunk == cb->end) if (cb->currentChunk == cb->end)
return cb->currentChunk; return cb->currentChunk;
next = cb->end + 1; next = successor(cb->end);
if (next >= buffered_chunks) {
next = 0;
}
while (cb->begin == next && !dc->stop) { while (cb->begin == next && !dc->stop) {
if (dc->seek) { if (dc->seek) {
if (seekable) { if (seekable) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment