use DIV_ROUND_UP()

This commit is contained in:
Boris Faure 2022-06-19 21:41:03 +02:00
parent 2c254526b9
commit 62a8e0a021
Signed by: borisfaure
GPG Key ID: EAA9CD729F522998
5 changed files with 26 additions and 22 deletions

View File

@ -13,17 +13,21 @@ notnull.cocci
null_ref.cocci
unused.cocci
use_after_iter.cocci
div_round_up.cocci
"
HAS_ERROR=0
for f in $COCCI_FILES; do
CMD="spatch --timeout 200 --very-quiet --cocci-file scripts/coccinelle/$f --include-headers --dir $DIR"
#CMD="spatch --very-quiet --cocci-file scripts/coccinelle/$f --dir $DIR -allow_inconsistent_paths"
OUT=$($CMD)
echo "$CMD"
if [ -n "$OUT" ]; then
echo "$OUT"
HAS_ERROR=1
fi
OPTIONS=""
if [ "$COCCI_FILES" = "div_round_up" ]; then
OPTIONS="--defined DIV_ROUND_UP"
fi
CMD="spatch --timeout 200 --very-quiet --cocci-file scripts/coccinelle/$f --include-headers --dir $DIR $OPTIONS"
OUT=$($CMD)
echo "$CMD"
if [ -n "$OUT" ]; then
echo "$OUT"
HAS_ERROR=1
fi
done
exit $HAS_ERROR

View File

@ -16,11 +16,11 @@ _accounting_change(int64_t diff)
{
if (diff > 0)
{
diff = ((diff + 16-1) / 16) * 16;
diff = DIV_ROUND_UP(diff, 16) * 16;
}
else
{
diff = ((-1 * diff + 16-1) / 16) * -16;
diff = DIV_ROUND_UP(-1 * diff, 16) * -16;
}
_mem_used += diff;
}
@ -167,7 +167,7 @@ termpty_backlog_length(Termpty *ty)
if (!ts->cells)
goto end;
nb_lines = (ts->w == 0) ? 1 : (ts->w + ty->w - 1) / ty->w;
nb_lines = (ts->w == 0) ? 1 : DIV_ROUND_UP(ts->w, ty->w);
screen_y += nb_lines;
ty->backlog_beacon.screen_y = screen_y;
ty->backlog_beacon.backlog_y = backlog_y;

View File

@ -147,7 +147,7 @@ _mouse_move_cb(void *data,
return;
iw = sqrt(eina_list_count(sd->items));
if (iw < 1) iw = 1;
ih = (eina_list_count(sd->items) + (iw - 1)) / iw;
ih = DIV_ROUND_UP(eina_list_count(sd->items), iw);
if (ih < 1) ih = 1;
evas_object_geometry_get(sd->self, &x, &y, &w, &h);
sw = w * sd->zoom;
@ -366,7 +366,7 @@ _layout(Sel *sd)
iw = sqrt(eina_list_count(sd->items));
if (iw < 1) iw = 1;
ih = (eina_list_count(sd->items) + (iw - 1)) / iw;
ih = DIV_ROUND_UP(eina_list_count(sd->items), iw);
if (ih < 1) ih = 1;
evas_object_geometry_get(sd->self, &ox, &oy, &ow, &oh);
w = ow * sd->zoom;

View File

@ -992,8 +992,8 @@ termpty_text_save_top(Termpty *ty, Termcell *cells, ssize_t w_max)
{
int old_len = ts->w;
termpty_save_expand(ty, ts, cells, w);
ty->backlog_beacon.screen_y += (ts->w + ty->w - 1) / ty->w
- (old_len + ty->w - 1) / ty->w;
ty->backlog_beacon.screen_y += DIV_ROUND_UP(ts->w, ty->w)
- DIV_ROUND_UP(old_len, ty->w);
return;
}
}
@ -1060,7 +1060,7 @@ termpty_backscroll_adjust(Termpty *ty, int *scroll)
*scroll = ty->backlog_beacon.screen_y;
return;
}
nb_lines = (ts->w == 0) ? 1 : (ts->w + ty->w - 1) / ty->w;
nb_lines = (ts->w == 0) ? 1 : DIV_ROUND_UP(ts->w, ty->w);
screen_y += nb_lines;
ty->backlog_beacon.screen_y = screen_y;
ty->backlog_beacon.backlog_y = backlog_y;
@ -1099,7 +1099,7 @@ _termpty_cellrow_from_beacon_get(Termpty *ty, int requested_y, ssize_t *wret)
{
return NULL;
}
nb_lines = (ts->w == 0) ? 1 : (ts->w + ty->w - 1) / ty->w;
nb_lines = (ts->w == 0) ? 1 : DIV_ROUND_UP(ts->w, ty->w);
/* Only update the beacon if working on different line than the one
* from the beacon */
@ -1130,7 +1130,7 @@ _termpty_cellrow_from_beacon_get(Termpty *ty, int requested_y, ssize_t *wret)
{
return NULL;
}
nb_lines = (ts->w == 0) ? 1 : (ts->w + ty->w - 1) / ty->w;
nb_lines = (ts->w == 0) ? 1 : DIV_ROUND_UP(ts->w, ty->w);
ty->backlog_beacon.screen_y = screen_y;
ty->backlog_beacon.backlog_y = backlog_y;

View File

@ -52,17 +52,17 @@ scaleterm(int w, int h, int *iw, int *ih)
if (w > (width * cw))
{
*iw = width;
*ih = ((h * (width * cw) / w) + (ch - 1)) / ch;
*ih = DIV_ROUND_UP((h * (width * cw) / w), ch);
}
else
{
*iw = (w + (cw - 1)) / cw;
*ih = (h + (ch - 1)) / ch;
*iw = DIV_ROUND_UP(w, cw);
*ih = DIV_ROUND_UP(h, ch);
}
if (maxh && *ih > maxh)
{
*ih = maxh;
*iw = ((w * (maxh * ch) / h) + (cw - 1)) / cw;
*iw = DIV_ROUND_UP((w * (maxh * ch) / h), cw);
}
}