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

[PATCH v2 1/6] shallow.c: rename fields in paint_info to better express their purposes

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Dec 6, 2016, 12:53 UTC
Message-ID
<20161206125339.16803-2-pclouds@gmail.com>
In-Reply-To
<20161206125339.16803-1-pclouds@gmail.com>

paint_alloc() is basically malloc(), tuned for allocating a fixed number of bits on every call without worrying about freeing any individual allocation since all will be freed at the end. It does it by allocating a big block of memory every time it runs out of "free memory". "slab" is a poor choice of name, at least poorer than "pool".

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 shallow.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/shallow.c b/shallow.c
index 4d0b005..8100dfd 100644
--- a/shallow.c
+++ b/shallow.c
@@ -434,9 +434,9 @@ define_commit_slab(ref_bitmap, uint32_t *);
 struct paint_info {
 	struct ref_bitmap ref_bitmap;
 	unsigned nr_bits;
-	char **slab;
+	char **pools;
 	char *free, *end;
-	unsigned slab_count;
+	unsigned pool_count;
 };
 
 static uint32_t *paint_alloc(struct paint_info *info)
@@ -444,11 +444,11 @@ static uint32_t *paint_alloc(struct paint_info *info)
 	unsigned nr = (info->nr_bits + 31) / 32;
 	unsigned size = nr * sizeof(uint32_t);
 	void *p;
-	if (!info->slab_count || info->free + size > info->end) {
-		info->slab_count++;
-		REALLOC_ARRAY(info->slab, info->slab_count);
+	if (!info->pool_count || info->free + size > info->end) {
+		info->pool_count++;
+		REALLOC_ARRAY(info->pools, info->pool_count);
 		info->free = xmalloc(COMMIT_SLAB_SIZE);
-		info->slab[info->slab_count - 1] = info->free;
+		info->pools[info->pool_count - 1] = info->free;
 		info->end = info->free + COMMIT_SLAB_SIZE;
 	}
 	p = info->free;
@@ -624,9 +624,9 @@ void assign_shallow_commits_to_refs(struct shallow_info *info,
 		post_assign_shallow(info, &pi.ref_bitmap, ref_status);
 
 	clear_ref_bitmap(&pi.ref_bitmap);
-	for (i = 0; i < pi.slab_count; i++)
-		free(pi.slab[i]);
-	free(pi.slab);
+	for (i = 0; i < pi.pool_count; i++)
+		free(pi.pools[i]);
+	free(pi.pools);
 	free(shallow);
 }
 
-- 
2.8.2.524.g6ff3d78
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 12 of 20 in “shallow.c: make paint_alloc slightly more robust”
  1. 1/4 shallow.c: make paint_alloc slightly more robustRasmus Villemoes, Dec 2, 2016
  2. 2/4 shallow.c: avoid theoretical pointer wrap-aroundRasmus Villemoes, Dec 2, 2016
  3. Jeff KingDec 3, 2016
  4. 3/4 shallow.c: bit manipulation tweaksRasmus Villemoes, Dec 2, 2016
  5. Jeff KingDec 3, 2016
  6. 4/4 shallow.c: remove useless testRasmus Villemoes, Dec 2, 2016
  7. Jeff KingDec 3, 2016
  8. Duy NguyenDec 5, 2016
  9. Jeff KingDec 3, 2016
  10. Duy NguyenDec 5, 2016
  11. 0/6 shallow.c improvementsNguyễn Thái Ngọc Duy, Dec 6, 2016
  12. 1/6 shallow.c: rename fields in paint_info to better express their purposesNguyễn Thái Ngọc Duy, Dec 6, 2016
  13. 5/6 shallow.c: bit manipulation tweaksNguyễn Thái Ngọc Duy, Dec 6, 2016
  14. 4/6 shallow.c: avoid theoretical pointer wrap-aroundNguyễn Thái Ngọc Duy, Dec 6, 2016
  15. 6/6 shallow.c: remove useless codeNguyễn Thái Ngọc Duy, Dec 6, 2016
  16. 3/6 shallow.c: make paint_alloc slightly more robustNguyễn Thái Ngọc Duy, Dec 6, 2016
  17. 2/6 shallow.c: stop abusing COMMIT_SLAB_SIZE for paint_info's memory poolsNguyễn Thái Ngọc Duy, Dec 6, 2016
  18. Jeff KingDec 6, 2016
  19. Duy NguyenDec 6, 2016
  20. Junio C HamanoDec 7, 2016

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.