Simplifying loops for performance: why check dropSamplesAtEnd in every
iteration, when we could modify the loop boundary?  The (writable)
variable samplesLeft can be eliminated; add a write-once variable
pcm_length instead, which is used for the loop condition.
---

 src/inputPlugins/mp3_plugin.c |   39 ++++++++++++++++++---------------------
 1 files changed, 18 insertions(+), 21 deletions(-)

diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c
index 7eb527e..2a6346b 100644
--- a/src/inputPlugins/mp3_plugin.c
+++ b/src/inputPlugins/mp3_plugin.c
@@ -839,7 +839,7 @@ static int openMp3FromInputStream(InputStream * inStream, 
mp3DecodeData * data,
 static int mp3Read(mp3DecodeData * data, struct decoder *decoder,
                   ReplayGainInfo ** replayGainInfo)
 {
-       unsigned int samplesLeft;
+       unsigned int pcm_length;
        unsigned int i;
        int ret;
        int skip;
@@ -917,32 +917,23 @@ static int mp3Read(mp3DecodeData * data, struct decoder 
*decoder,
                        freeMpdTag(tag);
                }
 
-               samplesLeft = (data->synth).pcm.length;
-
                if (!data->decodedFirstFrame) {
-                       if (data->dropSamplesAtStart >= samplesLeft) {
-                               i = samplesLeft;
-                               samplesLeft = 0;
-                       } else {
-                               i = data->dropSamplesAtStart;
-                               samplesLeft -= data->dropSamplesAtStart;
-                       }
+                       i = data->dropSamplesAtStart;
                        data->decodedFirstFrame = 1;
                } else
                        i = 0;
 
-               for (; i < (data->synth).pcm.length; i++) {
-                       unsigned int num_samples;
-
-                       samplesLeft--;
+               pcm_length = data->synth.pcm.length;
+               if (data->dropSamplesAtEnd &&
+                   (data->currentFrame == data->maxFrames - 
data->dropFramesAtEnd)) {
+                       if (data->dropSamplesAtEnd >= pcm_length)
+                               pcm_length = 0;
+                       else
+                               pcm_length -= data->dropSamplesAtEnd;
+               }
 
-                       if (data->dropSamplesAtEnd &&
-                                  (data->currentFrame == (data->maxFrames - 
data->dropFramesAtEnd)) &&
-                                  (samplesLeft < data->dropSamplesAtEnd)) {
-                               /* stop decoding, effectively dropping
-                                * all remaining samples */
-                               return DECODE_BREAK;
-                       }
+               for (; i < pcm_length; i++) {
+                       unsigned int num_samples;
 
                        num_samples = dither_buffer((mpd_sint16 *) 
data->outputPtr,
                                                    &data->synth, &data->dither,
@@ -968,6 +959,12 @@ static int mp3Read(mp3DecodeData * data, struct decoder 
*decoder,
                        }
                }
 
+               if (data->dropSamplesAtEnd &&
+                   (data->currentFrame == data->maxFrames - 
data->dropFramesAtEnd))
+                       /* stop decoding, effectively dropping
+                        * all remaining samples */
+                       return DECODE_BREAK;
+
                if (decoder_get_command(decoder) == DECODE_COMMAND_SEEK &&
                    data->inStream->seekable) {
                        unsigned long j = 0;


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Musicpd-dev-team mailing list
Musicpd-dev-team@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/musicpd-dev-team

Reply via email to