nsxiv29c6b14
code-style: reduce some unnecessary if-elses (#261)
also change the condition inside img_frame_animate() to check for positive value rather than comparing against 0.
+5 −16
2 files changed
- M commands.c +1 −4
- M image.c +4 −12
| @@ -273,10 +273,7 @@ bool ci_navigate(arg_t n) | |||
| 273 | 273 | if (prefix > 0) | |
| 274 | 274 | n *= prefix; | |
| 275 | 275 | n += fileidx; | |
| 276 | − | if (n < 0) | |
| 277 | − | n = 0; | |
| 278 | − | if (n >= filecnt) | |
| 279 | − | n = filecnt - 1; | |
| 276 | + | n = MAX(0, MIN(n, filecnt - 1)); | |
| 280 | 277 | ||
| 281 | 278 | if (n != fileidx) { | |
| 282 | 279 | load_image(n); | |
| @@ -898,23 +898,15 @@ bool img_frame_navigate(img_t *img, int d) | |||
| 898 | 898 | return false; | |
| 899 | 899 | ||
| 900 | 900 | d += img->multi.sel; | |
| 901 | − | if (d < 0) | |
| 902 | − | d = 0; | |
| 903 | − | else if (d >= img->multi.cnt) | |
| 904 | − | d = img->multi.cnt - 1; | |
| 901 | + | d = MAX(0, MIN(d, img->multi.cnt - 1)); | |
| 905 | 902 | ||
| 906 | 903 | return img_frame_goto(img, d); | |
| 907 | 904 | } | |
| 908 | 905 | ||
| 909 | 906 | bool img_frame_animate(img_t *img) | |
| 910 | 907 | { | |
| 911 | − | if (img->multi.cnt == 0) | |
| 912 | − | return false; | |
| 913 | − | ||
| 914 | − | if (img->multi.sel + 1 >= img->multi.cnt) | |
| 915 | − | img_frame_goto(img, 0); | |
| 908 | + | if (img->multi.cnt > 0) | |
| 909 | + | return img_frame_goto(img, (img->multi.sel + 1) % img->multi.cnt); | |
| 916 | 910 | else | |
| 917 | − | img_frame_goto(img, img->multi.sel + 1); | |
| 918 | − | img->dirty = true; | |
| 919 | − | return true; | |
| 911 | + | return false; | |
| 920 | 912 | } | |