From: Pierre Habouzit Date: Wed, 22 Jul 2009 21:34:35 +0000 (+0200) Subject: janitor: add DIV_ROUND_UP and use it. X-Git-Tag: v1.6.4-rc2~2 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=98cb6f30f708ef416572bf65bd26ac9f998ae0dc;p=git.git janitor: add DIV_ROUND_UP and use it. Signed-off-by: Pierre Habouzit Signed-off-by: Junio C Hamano --- diff --git a/git-compat-util.h b/git-compat-util.h index 6dfc0ddd9..9f941e42b 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -37,6 +37,8 @@ #define MSB(x, bits) ((x) & TYPEOF(x)(~0ULL << (bitsizeof(x) - (bits)))) #define HAS_MULTI_BITS(i) ((i) & ((i) - 1)) /* checks if an integer has more than 1 bit set */ +#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) + /* Approximation of the length of the decimal representation of this type. */ #define decimal_length(x) ((int)(sizeof(x) * 2.56 + 0.5) + 1) diff --git a/help.c b/help.c index fd87bb5ae..6c46d8b49 100644 --- a/help.c +++ b/help.c @@ -100,7 +100,7 @@ static void pretty_print_string_list(struct cmdnames *cmds, int longest) if (space < max_cols) cols = max_cols / space; - rows = (cmds->cnt + cols - 1) / cols; + rows = DIV_ROUND_UP(cmds->cnt, cols); for (i = 0; i < rows; i++) { printf(" "); diff --git a/preload-index.c b/preload-index.c index 14d528118..92899333c 100644 --- a/preload-index.c +++ b/preload-index.c @@ -76,7 +76,7 @@ static void preload_index(struct index_state *index, const char **pathspec) if (threads > MAX_PARALLEL) threads = MAX_PARALLEL; offset = 0; - work = (index->cache_nr + threads - 1) / threads; + work = DIV_ROUND_UP(index->cache_nr, threads); for (i = 0; i < threads; i++) { struct thread_data *p = data+i; p->index = index;