@matheusbsbs / matheus-bagliano / commits / 98cb6f30f7
Fork 0

janitor: add DIV_ROUND_UP and use it.

Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Pierre Habouzit committed Jul 22, 2009 at 23:34 UTC 98cb6f30f708ef416572bf65bd26ac9f998ae0dc
3 files changed +4 -2
git-compat-util.h
+2
@@ -37,6 +37,8 @@
37 #define MSB(x, bits) ((x) & TYPEOF(x)(~0ULL << (bitsizeof(x) - (bits))))
38 #define HAS_MULTI_BITS(i) ((i) & ((i) - 1)) /* checks if an integer has more than 1 bit set */
39
40 +#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
41 +
42 /* Approximation of the length of the decimal representation of this type. */
43 #define decimal_length(x) ((int)(sizeof(x) * 2.56 + 0.5) + 1)
44
help.c
+1 -1
@@ -100,7 +100,7 @@ static void pretty_print_string_list(struct cmdnames *cmds, int longest)
100
101 if (space < max_cols)
102 cols = max_cols / space;
103 - rows = (cmds->cnt + cols - 1) / cols;
103 + rows = DIV_ROUND_UP(cmds->cnt, cols);
104
105 for (i = 0; i < rows; i++) {
106 printf(" ");
preload-index.c
+1 -1
@@ -76,7 +76,7 @@ static void preload_index(struct index_state *index, const char **pathspec)
76 if (threads > MAX_PARALLEL)
77 threads = MAX_PARALLEL;
78 offset = 0;
79 - work = (index->cache_nr + threads - 1) / threads;
79 + work = DIV_ROUND_UP(index->cache_nr, threads);
80 for (i = 0; i < threads; i++) {
81 struct thread_data *p = data+i;
82 p->index = index;