git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: rv@rasmusvillemoes.dk, "Jeff King" <peff@peff.net>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH v2 1/6] shallow.c: rename fields in paint_info to better express their purposes
Date: Tue,  6 Dec 2016 19:53:34 +0700	[thread overview]
Message-ID: <20161206125339.16803-2-pclouds@gmail.com> (raw)
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


  reply	other threads:[~2016-12-06 12:55 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-02 20:31 [PATCH 1/4] shallow.c: make paint_alloc slightly more robust Rasmus Villemoes
2016-12-02 20:31 ` [PATCH 2/4] shallow.c: avoid theoretical pointer wrap-around Rasmus Villemoes
2016-12-03  5:17   ` Jeff King
2016-12-02 20:31 ` [PATCH 3/4] shallow.c: bit manipulation tweaks Rasmus Villemoes
2016-12-03  5:21   ` Jeff King
2016-12-02 20:31 ` [PATCH 4/4] shallow.c: remove useless test Rasmus Villemoes
2016-12-03  5:24   ` Jeff King
2016-12-05 12:00     ` Duy Nguyen
2016-12-03  5:14 ` [PATCH 1/4] shallow.c: make paint_alloc slightly more robust Jeff King
2016-12-05 10:02   ` Duy Nguyen
2016-12-06 12:53 ` [PATCH v2 0/6] shallow.c improvements Nguyễn Thái Ngọc Duy
2016-12-06 12:53   ` Nguyễn Thái Ngọc Duy [this message]
2016-12-06 12:53   ` [PATCH v2 2/6] shallow.c: stop abusing COMMIT_SLAB_SIZE for paint_info's memory pools Nguyễn Thái Ngọc Duy
2016-12-06 12:53   ` [PATCH v2 3/6] shallow.c: make paint_alloc slightly more robust Nguyễn Thái Ngọc Duy
2016-12-06 12:53   ` [PATCH v2 4/6] shallow.c: avoid theoretical pointer wrap-around Nguyễn Thái Ngọc Duy
2016-12-06 12:53   ` [PATCH v2 5/6] shallow.c: bit manipulation tweaks Nguyễn Thái Ngọc Duy
2016-12-06 12:53   ` [PATCH v2 6/6] shallow.c: remove useless code Nguyễn Thái Ngọc Duy
2016-12-06 13:42   ` [PATCH v2 0/6] shallow.c improvements Jeff King
2016-12-06 13:47     ` Duy Nguyen
2016-12-07 23:42       ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161206125339.16803-2-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    --cc=rv@rasmusvillemoes.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).