aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-04-12 04:14:55 +0000
committerEric Wong <normalperson@yhbt.net>2008-04-12 04:14:55 +0000
commit7503518bac267252307ac30802aeea9ff47ba80f (patch)
tree08f170b7aafbc78590e46bae10563d5f5497a377 /src
parent079f13bc7df49fec505d757e1ee4a8d55bcd0da1 (diff)
downloadmpd-7503518bac267252307ac30802aeea9ff47ba80f.tar.gz
mpd-7503518bac267252307ac30802aeea9ff47ba80f.tar.xz
mpd-7503518bac267252307ac30802aeea9ff47ba80f.zip
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
Diffstat (limited to '')
-rw-r--r--src/outputBuffer.c23
1 files 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) {