Git development
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Junio C Hamano <junkio@cox.net>, Git Mailing List <git@vger.kernel.org>
Subject: Re: Fix up ugly open-coded "alloc_nr()" user in object.c
Date: Sat, 16 Jun 2007 14:21:34 -0400	[thread overview]
Message-ID: <20070616182134.GA22003@coredump.intra.peff.net> (raw)
In-Reply-To: <alpine.LFD.0.98.0706161024220.14121@woody.linux-foundation.org>

On Sat, Jun 16, 2007 at 10:30:22AM -0700, Linus Torvalds wrote:

> When adding objects to the object/mode array, we used to have our own 
> alloc_nr() implementation, rather than use the normal one.
> 
> And since the normal one is arguably a bit nicer (still grows the 
> allocation exponentially, just not by more-than-doubling it every time), 
> why not just use it?

How about using the new ALLOC_GROW macro to make it even shorter? I also
got rid of the aliased variables, which IMO just make it harder to see
what's going on.

---
 object.c |   19 +++++--------------
 1 files changed, 5 insertions(+), 14 deletions(-)

diff --git a/object.c b/object.c
index 16793d9..064e423 100644
--- a/object.c
+++ b/object.c
@@ -240,18 +240,9 @@ void add_object_array(struct object *obj, const char *name, struct object_array
 
 void add_object_array_with_mode(struct object *obj, const char *name, struct object_array *array, unsigned mode)
 {
-	unsigned nr = array->nr;
-	unsigned alloc = array->alloc;
-	struct object_array_entry *objects = array->objects;
-
-	if (nr >= alloc) {
-		alloc = (alloc + 32) * 2;
-		objects = xrealloc(objects, alloc * sizeof(*objects));
-		array->alloc = alloc;
-		array->objects = objects;
-	}
-	objects[nr].item = obj;
-	objects[nr].name = name;
-	objects[nr].mode = mode;
-	array->nr = ++nr;
+	ALLOC_GROW(array->objects, array->nr, array->alloc);
+	array->objects[array->nr].item = obj;
+	array->objects[array->nr].name = name;
+	array->objects[array->nr].mode = mode;
+	array->nr++;
 }

  reply	other threads:[~2007-06-16 18:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-16 17:30 Fix up ugly open-coded "alloc_nr()" user in object.c Linus Torvalds
2007-06-16 18:21 ` Jeff King [this message]
2007-06-16 22:15   ` Olivier Galibert
2007-06-16 22:37     ` Jeff King

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

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

  git send-email \
    --in-reply-to=20070616182134.GA22003@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    --cc=torvalds@linux-foundation.org \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox