Skip to content

Commit 98cb6f3

Browse files
MadCodergitster
authored andcommitted
janitor: add DIV_ROUND_UP and use it.
Signed-off-by: Pierre Habouzit <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f630cfd commit 98cb6f3

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

git-compat-util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
#define MSB(x, bits) ((x) & TYPEOF(x)(~0ULL << (bitsizeof(x) - (bits))))
3838
#define HAS_MULTI_BITS(i) ((i) & ((i) - 1)) /* checks if an integer has more than 1 bit set */
3939

40+
#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
41+
4042
/* Approximation of the length of the decimal representation of this type. */
4143
#define decimal_length(x) ((int)(sizeof(x) * 2.56 + 0.5) + 1)
4244

help.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ static void pretty_print_string_list(struct cmdnames *cmds, int longest)
100100

101101
if (space < max_cols)
102102
cols = max_cols / space;
103-
rows = (cmds->cnt + cols - 1) / cols;
103+
rows = DIV_ROUND_UP(cmds->cnt, cols);
104104

105105
for (i = 0; i < rows; i++) {
106106
printf(" ");

preload-index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ static void preload_index(struct index_state *index, const char **pathspec)
7676
if (threads > MAX_PARALLEL)
7777
threads = MAX_PARALLEL;
7878
offset = 0;
79-
work = (index->cache_nr + threads - 1) / threads;
79+
work = DIV_ROUND_UP(index->cache_nr, threads);
8080
for (i = 0; i < threads; i++) {
8181
struct thread_data *p = data+i;
8282
p->index = index;

0 commit comments

Comments
 (0)