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

[PATCH 4/4] fast-import: use DIV_ROUND_UP

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Apr 11, 2012, 12:15 UTC
Message-ID
<20120411121531.GF19568@burratino>
In-Reply-To
<20120411121259.GB19568@burratino>
Date: Mon, 30 May 2011 22:45:43 -0500

fast-import keeps tree structures for reuse in pools arranged by size: one for trees with 0 entries, one for 8-entry trees, one for 16-entry trees, and so on up to 784-entry trees, plus another pool for larger trees. Use the DIV_ROUND_UP macro to determine which pool a given-sized tree belongs in to avoid some confusing bit-twiddling.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
Thanks for reading.
 fast-import.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/fast-import.c b/fast-import.c
index ebb27006..fc1b549d 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -785,7 +785,7 @@ static struct branch *new_branch(const char *name)
 
 static unsigned int hc_entries(unsigned int cnt)
 {
-	cnt = cnt & 7 ? (cnt / 8) + 1 : cnt / 8;
+	cnt = DIV_ROUND_UP(cnt, 8);
 	return cnt < avail_tree_table_sz ? cnt : avail_tree_table_sz - 1;
 }
 
@@ -805,7 +805,7 @@ static struct tree_content *new_tree_content(unsigned int cnt)
 		else
 			avail_tree_table[hc] = f->next_avail;
 	} else {
-		cnt = cnt & 7 ? ((cnt / 8) + 1) * 8 : cnt;
+		cnt = DIV_ROUND_UP(cnt, 8) * 8;
 		f = pool_alloc(sizeof(*t) + sizeof(t->entries[0]) * cnt);
 		f->entry_capacity = cnt;
 	}
-- 
1.7.10
Previous: Jonathan Nieder
Message 13 of 13 in “fast-import: use struct hash_table”
  1. David BarrMar 31, 2011
  2. 1/2 fast-import: use struct hash_table for atom stringsDavid Barr, Mar 31, 2011
  3. Jonathan NiederApr 2, 2011
  4. Jonathan NiederApr 2, 2011
  5. 2/2 fast-import: use struct hash_table for objectsDavid Barr, Mar 31, 2011
  6. Jonathan NiederApr 2, 2011
  7. Jonathan NiederApr 2, 2011
  8. 0/4 Re: fast-import: use struct hash_tableJonathan Nieder, Apr 11, 2012
  9. 0/4 Re: fast-import: use struct hash_tableJonathan Nieder, Apr 11, 2012
  10. 1/4 fast-import: allow object_table to grow dynamicallyJonathan Nieder, Apr 11, 2012
  11. 2/4 fast-import: allow atom_table to grow dynamicallyJonathan Nieder, Apr 11, 2012
  12. 3/4 fast-import: allow branch_table to grow dynamicallyJonathan Nieder, Apr 11, 2012
  13. 4/4 fast-import: use DIV_ROUND_UPJonathan Nieder, Apr 11, 2012

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.