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.
This commit is contained in:
N-R-K 2022-04-27 01:25:11 +00:00 committed by GitHub
parent 7fb8a61c47
commit 29c6b1456e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 16 deletions

View file

@ -273,10 +273,7 @@ bool ci_navigate(arg_t n)
if (prefix > 0) if (prefix > 0)
n *= prefix; n *= prefix;
n += fileidx; n += fileidx;
if (n < 0) n = MAX(0, MIN(n, filecnt - 1));
n = 0;
if (n >= filecnt)
n = filecnt - 1;
if (n != fileidx) { if (n != fileidx) {
load_image(n); load_image(n);

16
image.c
View file

@ -898,23 +898,15 @@ bool img_frame_navigate(img_t *img, int d)
return false; return false;
d += img->multi.sel; d += img->multi.sel;
if (d < 0) d = MAX(0, MIN(d, img->multi.cnt - 1));
d = 0;
else if (d >= img->multi.cnt)
d = img->multi.cnt - 1;
return img_frame_goto(img, d); return img_frame_goto(img, d);
} }
bool img_frame_animate(img_t *img) bool img_frame_animate(img_t *img)
{ {
if (img->multi.cnt == 0) if (img->multi.cnt > 0)
return false; return img_frame_goto(img, (img->multi.sel + 1) % img->multi.cnt);
if (img->multi.sel + 1 >= img->multi.cnt)
img_frame_goto(img, 0);
else else
img_frame_goto(img, img->multi.sel + 1); return false;
img->dirty = true;
return true;
} }