Git development
 help / color / mirror / Atom feed
* Fix up ugly open-coded "alloc_nr()" user in object.c
@ 2007-06-16 17:30 Linus Torvalds
  2007-06-16 18:21 ` Jeff King
  0 siblings, 1 reply; 4+ messages in thread
From: Linus Torvalds @ 2007-06-16 17:30 UTC (permalink / raw)
  To: Junio C Hamano, Git Mailing List


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;

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-06-16 22:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2007-06-16 22:15   ` Olivier Galibert
2007-06-16 22:37     ` Jeff King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox