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

Fix up ugly open-coded "alloc_nr()" user in object.c

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Jun 16, 2007, 17:30 UTC
Message-ID
<alpine.LFD.0.98.0706161024220.14121@woody.linux-foundation.org>

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?

That array of objects ends up being really quite big when you force a while repack of a big project, and while we might end up doing a few more xreallocs in the process, we also hopefully don't end up with a final allocation that is quite as wastefully big.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
---
  That was an overkill of a situation for a trivial patch that I don't 
  think is in the least interesting or even important. I really don't care 
  if you take this, Junio, but it seemed the obvious one-liner to do, so 
  I'm sending it in anyway.
 object.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/object.c b/object.c
index 16793d9..fdd6ceb 100644
--- a/object.c
+++ b/object.c
@@ -245,7 +245,7 @@ void add_object_array_with_mode(struct object *obj, const char *name, struct obj
 	struct object_array_entry *objects = array->objects;
 
 	if (nr >= alloc) {
-		alloc = (alloc + 32) * 2;
+		alloc = alloc_nr(alloc);
 		objects = xrealloc(objects, alloc * sizeof(*objects));
 		array->alloc = alloc;
 		array->objects = objects;
Next: Jeff King
Message 1 of 4 in “Fix up ugly open-coded "alloc_nr()" user in object.c”
  1. Linus TorvaldsJun 16, 2007
  2. Jeff KingJun 16, 2007
  3. Olivier GalibertJun 16, 2007
  4. Jeff KingJun 16, 2007

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.