[FFmpeg-devel] [PATCH] ffplay: compact expression in compute_mod()

Michael Niedermayer michaelni at gmx.at
Mon Apr 11 12:07:58 CEST 2011


On Mon, Apr 11, 2011 at 11:13:22AM +0200, Stefano Sabatini wrote:
> Prefer "return X ? Y : Z" over "if (x) return Y; else return Z",
> reduce line count.
> 
> Signed-off-by: Stefano Sabatini <stefano.sabatini-lala at poste.it>
> ---
>  ffplay.c |    5 +----
>  1 files changed, 1 insertions(+), 4 deletions(-)
> 
> diff --git a/ffplay.c b/ffplay.c
> index 04e0343..a5f3b70 100644
> --- a/ffplay.c
> +++ b/ffplay.c
> @@ -772,10 +772,7 @@ static void video_image_display(VideoState *is)
>  static inline int compute_mod(int a, int b)
>  {
>      a = a % b;
> -    if (a >= 0)
> -        return a;
> -    else
> -        return a + b;
> +    return a >= 0 ? a : a + b;
>  }

shortest:
return (a%b+b)%b;

maybe a hair faster than shortest:
return a<0 ? a%b+b : a%b;

either way all 3 variants ok, pick what you prefer

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Why not whip the teacher when the pupil misbehaves? -- Diogenes of Sinope
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20110411/267a806c/attachment.asc>


More information about the ffmpeg-devel mailing list