git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/3] janitor: add DIV_ROUND_UP and use it.

From
Pierre Habouzit <madcoder@debian.org>
Date
Jul 22, 2009, 21:34 UTC
Message-ID
<1248298475-2990-4-git-send-email-madcoder@debian.org>
In-Reply-To
<1248298475-2990-3-git-send-email-madcoder@debian.org>
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
---
 git-compat-util.h |    2 ++
 help.c            |    2 +-
 preload-index.c   |    2 +-
 3 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/git-compat-util.h b/git-compat-util.h
index 6dfc0dd..9f941e4 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 fd87bb5..6c46d8b 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 14d5281..9289933 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;
-- 
1.6.4.rc1.192.g631f9
Previous: Pierre HabouzitNext: Jeff King
Message 4 of 14 in “janitoring”
  1. Pierre HabouzitJul 22, 2009
  2. 1/3 janitor: use NULL and not 0 for pointers.Pierre Habouzit, Jul 22, 2009
  3. 2/3 refactor: use bitsizeof() instead of 8 * sizeof()Pierre Habouzit, Jul 22, 2009
  4. 3/3 janitor: add DIV_ROUND_UP and use it.Pierre Habouzit, Jul 22, 2009
  5. Jeff KingJul 23, 2009
  6. Junio C HamanoJul 23, 2009
  7. Jeff KingJul 23, 2009
  8. Junio C HamanoJul 23, 2009
  9. Pierre HabouzitJul 23, 2009
  10. Junio C HamanoJul 22, 2009
  11. Pierre HabouzitJul 22, 2009
  12. Junio C HamanoJul 22, 2009
  13. Johannes SchindelinJul 22, 2009
  14. Johannes SixtJul 23, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.