{"thread":{"id":"4576","subject":"Add \"named object array\" concept","startedAt":"2006-06-20T00:42:35Z","lastAt":"2006-06-20T00:42:35Z","messageCount":1,"participants":["Linus Torvalds"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"22089","messageId":"Pine.LNX.4.64.0606191726160.5498@g5.osdl.org","threadId":"4576","inReplyTo":null,"subject":"Add \"named object array\" concept","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2006-06-20T00:42:35Z","receivedAt":"2006-06-20T00:42:35Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\nWe've had this notion of a \"object_list\" for a long time, which eventually \ngrew a \"name\" member because some users (notably git-rev-list) wanted to \nname each object as it is generated.\n\nThat object_list is great for some things, but it isn't all that wonderful \nfor others, and the \"name\" member is generally not used by everybody.\n\nThis patch splits the users of the object_list array up into two: the \ntraditional list users, who want the list-like format, and who don't \nactually use or want the name. And another class of users that really used \nthe list as an extensible array, and generally wanted to name the objects.\n\nThe patch is fairly straightforward, but it's also biggish. Most of it \nreally just cleans things up: switching the revision parsing and listing \nover to the array makes things like the builtin-diff usage much simpler \n(we now see exactly how many members the array has, and we don't get the \nobjects reversed from the order they were on the command line).\n\nOne of the main reasons for doing this at all is that the malloc overhead \nof the simple object list was actually pretty high, and the array is just \na lot denser. So this patch brings down memory usage by git-rev-list by \njust under 3% (on top of all the other memory use optimizations) on the \nmozilla archive.\n\nIt does add more lines than it removes, and more importantly, it adds a \nwhole new infrastructure for maintaining lists of objects, but on the \nother hand, the new dynamic array code is pretty obvious. The change to \nbuiltin-diff-tree.c shows a fairly good example of why an array interface \nis sometimes more natural, and just much simpler for everybody.\n\nSigned-off-by: Linus Torvalds <torvalds@osdl.org>\n---\n\nBtw, somebody should really check my http-push conversion.\n\nIt actually used to set up the whole \"name\" thing, and it still has the \ncode for it, but there really is no point to it, and as far as I can tell, \nit never _used_ it. It just had it because the code was copied from \ngit-rev-list, I suspect.\n\nSo there's room for further simplification there, but I wanted to leave \nthat part as a minimal patch, just because I don't use it, and while I'm \npretty damn sure that the \"name\" part was never actually used (the fact \nthat it compiles fine without any \"name\" in the object list at all is a \nbig hint ;), it should get somebody else looking over my diff. And \nsimplifying the code later.\n\n builtin-diff-files.c |    2 +-\n builtin-diff-index.c |    2 +-\n builtin-diff-tree.c  |   42 +++++++++------------------------\n builtin-diff.c       |   26 +++++++++++---------\n builtin-grep.c       |   16 +++++--------\n builtin-log.c        |    4 ++-\n builtin-rev-list.c   |   64 ++++++++++++++++++++++++++------------------------\n diff-lib.c           |    4 ++-\n http-push.c          |   28 +++++++++++++++-------\n name-rev.c           |   17 +++++++------\n object.c             |   17 +++++++++++++\n object.h             |   13 +++++++++-\n revision.c           |   33 ++++++++++++--------------\n revision.h           |   12 +++++----\n 14 files changed, 150 insertions(+), 130 deletions(-)\n\ndiff --git a/builtin-diff-files.c b/builtin-diff-files.c\nindex cebda82..5afc1d7 100644\n--- a/builtin-diff-files.c\n+++ b/builtin-diff-files.c\n@@ -41,7 +41,7 @@ int cmd_diff_files(int argc, const char \n \t * rev.max_count is reasonable (0 <= n <= 3),\n \t * there is no other revision filtering parameters.\n \t */\n-\tif (rev.pending_objects ||\n+\tif (rev.pending.nr ||\n \t    rev.min_age != -1 || rev.max_age != -1)\n \t\tusage(diff_files_usage);\n \t/*\ndiff --git a/builtin-diff-index.c b/builtin-diff-index.c\nindex 1958580..c42ef9a 100644\n--- a/builtin-diff-index.c\n+++ b/builtin-diff-index.c\n@@ -32,7 +32,7 @@ int cmd_diff_index(int argc, const char \n \t * Make sure there is one revision (i.e. pending object),\n \t * and there is no revision filtering parameters.\n \t */\n-\tif (!rev.pending_objects || rev.pending_objects->next ||\n+\tif (rev.pending.nr != 1 ||\n \t    rev.max_count != -1 || rev.min_age != -1 || rev.max_age != -1)\n \t\tusage(diff_cache_usage);\n \treturn run_diff_index(&rev, cached);\ndiff --git a/builtin-diff-tree.c b/builtin-diff-tree.c\nindex 58cf658..3409a39 100644\n--- a/builtin-diff-tree.c\n+++ b/builtin-diff-tree.c\n@@ -65,7 +65,6 @@ int cmd_diff_tree(int argc, const char *\n \tchar line[1000];\n \tstruct object *tree1, *tree2;\n \tstatic struct rev_info *opt = &log_tree_opt;\n-\tstruct object_list *list;\n \tint read_stdin = 0;\n \n \tgit_config(git_diff_config);\n@@ -86,45 +85,28 @@ int cmd_diff_tree(int argc, const char *\n \t}\n \n \t/*\n-\t * NOTE! \"setup_revisions()\" will have inserted the revisions\n-\t * it parsed in reverse order. So if you do\n-\t *\n-\t *\tgit-diff-tree a b\n-\t *\n-\t * the commit list will be \"b\" -> \"a\" -> NULL, so we reverse\n-\t * the order of the objects if the first one is not marked\n-\t * UNINTERESTING.\n+\t * NOTE! We expect \"a ^b\" to be equal to \"a..b\", so we\n+\t * reverse the order of the objects if the second one\n+\t * is marked UNINTERESTING.\n \t */\n-\tnr_sha1 = 0;\n-\tlist = opt->pending_objects;\n-\tif (list) {\n-\t\tnr_sha1++;\n-\t\ttree1 = list->item;\n-\t\tlist = list->next;\n-\t\tif (list) {\n-\t\t\tnr_sha1++;\n-\t\t\ttree2 = tree1;\n-\t\t\ttree1 = list->item;\n-\t\t\tif (list->next)\n-\t\t\t\tusage(diff_tree_usage);\n-\t\t\t/* Switch them around if the second one was uninteresting.. */\n-\t\t\tif (tree2->flags & UNINTERESTING) {\n-\t\t\t\tstruct object *tmp = tree2;\n-\t\t\t\ttree2 = tree1;\n-\t\t\t\ttree1 = tmp;\n-\t\t\t}\n-\t\t}\n-\t}\n-\n+\tnr_sha1 = opt->pending.nr;\n \tswitch (nr_sha1) {\n \tcase 0:\n \t\tif (!read_stdin)\n \t\t\tusage(diff_tree_usage);\n \t\tbreak;\n \tcase 1:\n+\t\ttree1 = opt->pending.objects[0].item;\n \t\tdiff_tree_commit_sha1(tree1->sha1);\n \t\tbreak;\n \tcase 2:\n+\t\ttree1 = opt->pending.objects[0].item;\n+\t\ttree2 = opt->pending.objects[1].item;\n+\t\tif (tree2->flags & UNINTERESTING) {\n+\t\t\tstruct object *tmp = tree2;\n+\t\t\ttree2 = tree1;\n+\t\t\ttree1 = tmp;\n+\t\t}\n \t\tdiff_tree_sha1(tree1->sha1,\n \t\t\t       tree2->sha1,\n \t\t\t       \"\", &opt->diffopt);\ndiff --git a/builtin-diff.c b/builtin-diff.c\nindex 6ac3d4b..99a2f76 100644\n--- a/builtin-diff.c\n+++ b/builtin-diff.c\n@@ -50,7 +50,7 @@ static int builtin_diff_files(struct rev\n \t * specified rev.max_count is reasonable (0 <= n <= 3), and\n \t * there is no other revision filtering parameter.\n \t */\n-\tif (revs->pending_objects ||\n+\tif (revs->pending.nr ||\n \t    revs->min_age != -1 ||\n \t    revs->max_age != -1 ||\n \t    3 < revs->max_count)\n@@ -172,7 +172,7 @@ static int builtin_diff_index(struct rev\n \t * Make sure there is one revision (i.e. pending object),\n \t * and there is no revision filtering parameters.\n \t */\n-\tif (!revs->pending_objects || revs->pending_objects->next ||\n+\tif (revs->pending.nr != 1 ||\n \t    revs->max_count != -1 || revs->min_age != -1 ||\n \t    revs->max_age != -1)\n \t\tusage(builtin_diff_usage);\n@@ -181,10 +181,10 @@ static int builtin_diff_index(struct rev\n \n static int builtin_diff_tree(struct rev_info *revs,\n \t\t\t     int argc, const char **argv,\n-\t\t\t     struct object_list *ent)\n+\t\t\t     struct object_array_entry *ent)\n {\n \tconst unsigned char *(sha1[2]);\n-\tint swap = 1;\n+\tint swap = 0;\n \twhile (1 < argc) {\n \t\tconst char *arg = argv[1];\n \t\tif (!strcmp(arg, \"--raw\"))\n@@ -195,10 +195,10 @@ static int builtin_diff_tree(struct rev_\n \t}\n \n \t/* We saw two trees, ent[0] and ent[1].\n-\t * unless ent[0] is unintesting, they are swapped\n+\t * if ent[1] is unintesting, they are swapped\n \t */\n-\tif (ent[0].item->flags & UNINTERESTING)\n-\t\tswap = 0;\n+\tif (ent[1].item->flags & UNINTERESTING)\n+\t\tswap = 1;\n \tsha1[swap] = ent[0].item->sha1;\n \tsha1[1-swap] = ent[1].item->sha1;\n \tdiff_tree_sha1(sha1[0], sha1[1], \"\", &revs->diffopt);\n@@ -208,7 +208,7 @@ static int builtin_diff_tree(struct rev_\n \n static int builtin_diff_combined(struct rev_info *revs,\n \t\t\t\t int argc, const char **argv,\n-\t\t\t\t struct object_list *ent,\n+\t\t\t\t struct object_array_entry *ent,\n \t\t\t\t int ents)\n {\n \tconst unsigned char (*parent)[20];\n@@ -242,13 +242,14 @@ void add_head(struct rev_info *revs)\n \tobj = parse_object(sha1);\n \tif (!obj)\n \t\treturn;\n-\tadd_object(obj, &revs->pending_objects, NULL, \"HEAD\");\n+\tadd_pending_object(revs, obj, \"HEAD\");\n }\n \n int cmd_diff(int argc, const char **argv, char **envp)\n {\n+\tint i;\n \tstruct rev_info rev;\n-\tstruct object_list *list, ent[100];\n+\tstruct object_array_entry ent[100];\n \tint ents = 0, blobs = 0, paths = 0;\n \tconst char *path = NULL;\n \tstruct blobinfo blob[2];\n@@ -281,7 +282,7 @@ int cmd_diff(int argc, const char **argv\n \t/* Do we have --cached and not have a pending object, then\n \t * default to HEAD by hand.  Eek.\n \t */\n-\tif (!rev.pending_objects) {\n+\tif (!rev.pending.nr) {\n \t\tint i;\n \t\tfor (i = 1; i < argc; i++) {\n \t\t\tconst char *arg = argv[i];\n@@ -294,7 +295,8 @@ int cmd_diff(int argc, const char **argv\n \t\t}\n \t}\n \n-\tfor (list = rev.pending_objects; list; list = list->next) {\n+\tfor (i = 0; i < rev.pending.nr; i++) {\n+\t\tstruct object_array_entry *list = rev.pending.objects+i;\n \t\tstruct object *obj = list->item;\n \t\tconst char *name = list->name;\n \t\tint flags = (obj->flags & UNINTERESTING);\ndiff --git a/builtin-grep.c b/builtin-grep.c\nindex 9806499..6a240fb 100644\n--- a/builtin-grep.c\n+++ b/builtin-grep.c\n@@ -657,7 +657,7 @@ int cmd_grep(int argc, const char **argv\n \tint cached = 0;\n \tint seen_dashdash = 0;\n \tstruct grep_opt opt;\n-\tstruct object_list *list, **tail, *object_list = NULL;\n+\tstruct object_array list = { 0, 0, NULL };\n \tconst char *prefix = setup_git_directory();\n \tconst char **paths = NULL;\n \tint i;\n@@ -677,7 +677,6 @@ int cmd_grep(int argc, const char **argv\n \t * that continues up to the -- (if exists), and then paths.\n \t */\n \n-\ttail = &object_list;\n \twhile (1 < argc) {\n \t\tconst char *arg = argv[1];\n \t\targc--; argv++;\n@@ -851,12 +850,9 @@ int cmd_grep(int argc, const char **argv\n \t\t/* Is it a rev? */\n \t\tif (!get_sha1(arg, sha1)) {\n \t\t\tstruct object *object = parse_object(sha1);\n-\t\t\tstruct object_list *elem;\n \t\t\tif (!object)\n \t\t\t\tdie(\"bad object %s\", arg);\n-\t\t\telem = object_list_insert(object, tail);\n-\t\t\telem->name = arg;\n-\t\t\ttail = &elem->next;\n+\t\t\tadd_object_array(object, arg, &list);\n \t\t\tcontinue;\n \t\t}\n \t\tif (!strcmp(arg, \"--\")) {\n@@ -881,16 +877,16 @@ int cmd_grep(int argc, const char **argv\n \t\tpaths[1] = NULL;\n \t}\n \n-\tif (!object_list)\n+\tif (!list.nr)\n \t\treturn !grep_cache(&opt, paths, cached);\n \n \tif (cached)\n \t\tdie(\"both --cached and trees are given.\");\n \n-\tfor (list = object_list; list; list = list->next) {\n+\tfor (i = 0; i < list.nr; i++) {\n \t\tstruct object *real_obj;\n-\t\treal_obj = deref_tag(list->item, NULL, 0);\n-\t\tif (grep_object(&opt, paths, real_obj, list->name))\n+\t\treal_obj = deref_tag(list.objects[i].item, NULL, 0);\n+\t\tif (grep_object(&opt, paths, real_obj, list.objects[i].name))\n \t\t\thit = 1;\n \t}\n \treturn !hit;\ndiff --git a/builtin-log.c b/builtin-log.c\nindex 9187fd3..5a8a50b 100644\n--- a/builtin-log.c\n+++ b/builtin-log.c\n@@ -257,8 +257,8 @@ int cmd_format_patch(int argc, const cha\n \t\t\t    output_directory);\n \t}\n \n-\tif (rev.pending_objects && rev.pending_objects->next == NULL) {\n-\t\trev.pending_objects->item->flags |= UNINTERESTING;\n+\tif (rev.pending.nr == 1) {\n+\t\trev.pending.objects[0].item->flags |= UNINTERESTING;\n \t\tadd_head(&rev);\n \t}\n \ndiff --git a/builtin-rev-list.c b/builtin-rev-list.c\nindex 71353eb..63bad0e 100644\n--- a/builtin-rev-list.c\n+++ b/builtin-rev-list.c\n@@ -99,26 +99,26 @@ static void show_commit(struct commit *c\n \t}\n }\n \n-static struct object_list **process_blob(struct blob *blob,\n-\t\t\t\t\t struct object_list **p,\n-\t\t\t\t\t struct name_path *path,\n-\t\t\t\t\t const char *name)\n+static void process_blob(struct blob *blob,\n+\t\t\t struct object_array *p,\n+\t\t\t struct name_path *path,\n+\t\t\t const char *name)\n {\n \tstruct object *obj = &blob->object;\n \n \tif (!revs.blob_objects)\n-\t\treturn p;\n+\t\treturn;\n \tif (obj->flags & (UNINTERESTING | SEEN))\n-\t\treturn p;\n+\t\treturn;\n \tobj->flags |= SEEN;\n \tname = strdup(name);\n-\treturn add_object(obj, p, path, name);\n+\tadd_object(obj, p, path, name);\n }\n \n-static struct object_list **process_tree(struct tree *tree,\n-\t\t\t\t\t struct object_list **p,\n-\t\t\t\t\t struct name_path *path,\n-\t\t\t\t\t const char *name)\n+static void process_tree(struct tree *tree,\n+\t\t\t struct object_array *p,\n+\t\t\t struct name_path *path,\n+\t\t\t const char *name)\n {\n \tstruct object *obj = &tree->object;\n \tstruct tree_desc desc;\n@@ -126,14 +126,14 @@ static struct object_list **process_tree\n \tstruct name_path me;\n \n \tif (!revs.tree_objects)\n-\t\treturn p;\n+\t\treturn;\n \tif (obj->flags & (UNINTERESTING | SEEN))\n-\t\treturn p;\n+\t\treturn;\n \tif (parse_tree(tree) < 0)\n \t\tdie(\"bad tree object %s\", sha1_to_hex(obj->sha1));\n \tobj->flags |= SEEN;\n \tname = strdup(name);\n-\tp = add_object(obj, p, path, name);\n+\tadd_object(obj, p, path, name);\n \tme.up = path;\n \tme.elem = name;\n \tme.elem_len = strlen(name);\n@@ -143,57 +143,59 @@ static struct object_list **process_tree\n \n \twhile (tree_entry(&desc, &entry)) {\n \t\tif (S_ISDIR(entry.mode))\n-\t\t\tp = process_tree(lookup_tree(entry.sha1), p, &me, entry.path);\n+\t\t\tprocess_tree(lookup_tree(entry.sha1), p, &me, entry.path);\n \t\telse\n-\t\t\tp = process_blob(lookup_blob(entry.sha1), p, &me, entry.path);\n+\t\t\tprocess_blob(lookup_blob(entry.sha1), p, &me, entry.path);\n \t}\n \tfree(tree->buffer);\n \ttree->buffer = NULL;\n-\treturn p;\n }\n \n static void show_commit_list(struct rev_info *revs)\n {\n+\tint i;\n \tstruct commit *commit;\n-\tstruct object_list *objects = NULL, **p = &objects, *pending;\n+\tstruct object_array objects = { 0, 0, NULL };\n \n \twhile ((commit = get_revision(revs)) != NULL) {\n-\t\tp = process_tree(commit->tree, p, NULL, \"\");\n+\t\tprocess_tree(commit->tree, &objects, NULL, \"\");\n \t\tshow_commit(commit);\n \t}\n-\tfor (pending = revs->pending_objects; pending; pending = pending->next) {\n+\tfor (i = 0; i < revs->pending.nr; i++) {\n+\t\tstruct object_array_entry *pending = revs->pending.objects + i;\n \t\tstruct object *obj = pending->item;\n \t\tconst char *name = pending->name;\n \t\tif (obj->flags & (UNINTERESTING | SEEN))\n \t\t\tcontinue;\n \t\tif (obj->type == TYPE_TAG) {\n \t\t\tobj->flags |= SEEN;\n-\t\t\tp = add_object(obj, p, NULL, name);\n+\t\t\tadd_object_array(obj, name, &objects);\n \t\t\tcontinue;\n \t\t}\n \t\tif (obj->type == TYPE_TREE) {\n-\t\t\tp = process_tree((struct tree *)obj, p, NULL, name);\n+\t\t\tprocess_tree((struct tree *)obj, &objects, NULL, name);\n \t\t\tcontinue;\n \t\t}\n \t\tif (obj->type == TYPE_BLOB) {\n-\t\t\tp = process_blob((struct blob *)obj, p, NULL, name);\n+\t\t\tprocess_blob((struct blob *)obj, &objects, NULL, name);\n \t\t\tcontinue;\n \t\t}\n \t\tdie(\"unknown pending object %s (%s)\", sha1_to_hex(obj->sha1), name);\n \t}\n-\twhile (objects) {\n+\tfor (i = 0; i < objects.nr; i++) {\n+\t\tstruct object_array_entry *p = objects.objects + i;\n+\n \t\t/* An object with name \"foo\\n0000000...\" can be used to\n \t\t * confuse downstream git-pack-objects very badly.\n \t\t */\n-\t\tconst char *ep = strchr(objects->name, '\\n');\n+\t\tconst char *ep = strchr(p->name, '\\n');\n \t\tif (ep) {\n-\t\t\tprintf(\"%s %.*s\\n\", sha1_to_hex(objects->item->sha1),\n-\t\t\t       (int) (ep - objects->name),\n-\t\t\t       objects->name);\n+\t\t\tprintf(\"%s %.*s\\n\", sha1_to_hex(p->item->sha1),\n+\t\t\t       (int) (ep - p->name),\n+\t\t\t       p->name);\n \t\t}\n \t\telse\n-\t\t\tprintf(\"%s %s\\n\", sha1_to_hex(objects->item->sha1), objects->name);\n-\t\tobjects = objects->next;\n+\t\t\tprintf(\"%s %s\\n\", sha1_to_hex(p->item->sha1), p->name);\n \t}\n }\n \n@@ -348,7 +350,7 @@ int cmd_rev_list(int argc, const char **\n \n \tif ((!list &&\n \t     (!(revs.tag_objects||revs.tree_objects||revs.blob_objects) &&\n-\t      !revs.pending_objects)) ||\n+\t      !revs.pending.nr)) ||\n \t    revs.diff)\n \t\tusage(rev_list_usage);\n \ndiff --git a/diff-lib.c b/diff-lib.c\nindex 2183b41..d93cd55 100644\n--- a/diff-lib.c\n+++ b/diff-lib.c\n@@ -329,8 +329,8 @@ int run_diff_index(struct rev_info *revs\n \t}\n \tmark_merge_entries();\n \n-\tent = revs->pending_objects->item;\n-\ttree_name = revs->pending_objects->name;\n+\tent = revs->pending.objects[0].item;\n+\ttree_name = revs->pending.objects[0].name;\n \ttree = parse_tree_indirect(ent->sha1);\n \tif (!tree)\n \t\treturn error(\"bad tree object %s\", tree_name);\ndiff --git a/http-push.c b/http-push.c\nindex ba64f8f..0f02a55 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -1171,7 +1171,7 @@ static void one_remote_object(const char\n \n \tobj->flags |= REMOTE;\n \tif (!object_list_contains(objects, obj))\n-\t\tadd_object(obj, &objects, NULL, \"\");\n+\t\tobject_list_insert(obj, &objects);\n }\n \n static void handle_lockprop_ctx(struct xml_ctx *ctx, int tag_closed)\n@@ -1699,6 +1699,15 @@ static int locking_available(void)\n \treturn lock_flags;\n }\n \n+struct object_list **add_one_object(struct object *obj, struct object_list **p)\n+{\n+\tstruct object_list *entry = xmalloc(sizeof(struct object_list));\n+\tentry->item = obj;\n+\tentry->next = *p;\n+\t*p = entry;\n+\treturn &entry->next;\n+}\n+\n static struct object_list **process_blob(struct blob *blob,\n \t\t\t\t\t struct object_list **p,\n \t\t\t\t\t struct name_path *path,\n@@ -1712,8 +1721,7 @@ static struct object_list **process_blob\n \t\treturn p;\n \n \tobj->flags |= SEEN;\n-\tname = strdup(name);\n-\treturn add_object(obj, p, path, name);\n+\treturn add_one_object(obj, p);\n }\n \n static struct object_list **process_tree(struct tree *tree,\n@@ -1735,7 +1743,7 @@ static struct object_list **process_tree\n \n \tobj->flags |= SEEN;\n \tname = strdup(name);\n-\tp = add_object(obj, p, NULL, name);\n+\tp = add_one_object(obj, p);\n \tme.up = path;\n \tme.elem = name;\n \tme.elem_len = strlen(name);\n@@ -1756,8 +1764,9 @@ static struct object_list **process_tree\n \n static int get_delta(struct rev_info *revs, struct remote_lock *lock)\n {\n+\tint i;\n \tstruct commit *commit;\n-\tstruct object_list **p = &objects, *pending;\n+\tstruct object_list **p = &objects;\n \tint count = 0;\n \n \twhile ((commit = get_revision(revs)) != NULL) {\n@@ -1767,15 +1776,16 @@ static int get_delta(struct rev_info *re\n \t\t\tcount += add_send_request(&commit->object, lock);\n \t}\n \n-\tfor (pending = revs->pending_objects; pending; pending = pending->next) {\n-\t\tstruct object *obj = pending->item;\n-\t\tconst char *name = pending->name;\n+\tfor (i = 0; i < revs->pending.nr; i++) {\n+\t\tstruct object_array_entry *entry = revs->pending.objects + i;\n+\t\tstruct object *obj = entry->item;\n+\t\tconst char *name = entry->name;\n \n \t\tif (obj->flags & (UNINTERESTING | SEEN))\n \t\t\tcontinue;\n \t\tif (obj->type == TYPE_TAG) {\n \t\t\tobj->flags |= SEEN;\n-\t\t\tp = add_object(obj, p, NULL, name);\n+\t\t\tp = add_one_object(obj, p);\n \t\t\tcontinue;\n \t\t}\n \t\tif (obj->type == TYPE_TREE) {\ndiff --git a/name-rev.c b/name-rev.c\nindex c29b93e..586d842 100644\n--- a/name-rev.c\n+++ b/name-rev.c\n@@ -128,8 +128,7 @@ static const char* get_rev_name(struct o\n \t\n int main(int argc, char **argv)\n {\n-\tstruct object_list *revs = NULL;\n-\tstruct object_list **walker = &revs;\n+\tstruct object_array revs = { 0, 0, NULL };\n \tint as_is = 0, all = 0, transform_stdin = 0;\n \n \tsetup_git_directory();\n@@ -184,9 +183,7 @@ int main(int argc, char **argv)\n \t\tif (cutoff > commit->date)\n \t\t\tcutoff = commit->date;\n \n-\t\tobject_list_append((struct object *)commit, walker);\n-\t\t(*walker)->name = *argv;\n-\t\twalker = &((*walker)->next);\n+\t\tadd_object_array((struct object *)commit, *argv, &revs);\n \t}\n \n \tfor_each_ref(name_ref);\n@@ -243,9 +240,13 @@ #define ishex(x) (isdigit((x)) || ((x) >\n \t\t\tif (objs[i])\n \t\t\t\tprintf(\"%s %s\\n\", sha1_to_hex(objs[i]->sha1),\n \t\t\t\t\t\tget_rev_name(objs[i]));\n-\t} else\n-\t\tfor ( ; revs; revs = revs->next)\n-\t\t\tprintf(\"%s %s\\n\", revs->name, get_rev_name(revs->item));\n+\t} else {\n+\t\tint i;\n+\t\tfor (i = 0; i < revs.nr; i++)\n+\t\t\tprintf(\"%s %s\\n\",\n+\t\t\t\trevs.objects[i].name,\n+\t\t\t\tget_rev_name(revs.objects[i].item));\n+\t}\n \n \treturn 0;\n }\ndiff --git a/object.c b/object.c\nindex e26e319..37784ce 100644\n--- a/object.c\n+++ b/object.c\n@@ -200,3 +200,20 @@ int object_list_contains(struct object_l\n \t}\n \treturn 0;\n }\n+\n+void add_object_array(struct object *obj, const char *name, struct object_array *array)\n+{\n+\tunsigned nr = array->nr;\n+\tunsigned alloc = array->alloc;\n+\tstruct object_array_entry *objects = array->objects;\n+\n+\tif (nr >= alloc) {\n+\t\talloc = (alloc + 32) * 2;\n+\t\tobjects = xrealloc(objects, alloc * sizeof(*objects));\n+\t\tarray->alloc = alloc;\n+\t\tarray->objects = objects;\n+\t}\n+\tobjects[nr].item = obj;\n+\tobjects[nr].name = name;\n+\tarray->nr = ++nr;\n+}\ndiff --git a/object.h b/object.h\nindex c537b4b..6f23a9a 100644\n--- a/object.h\n+++ b/object.h\n@@ -4,7 +4,6 @@ #define OBJECT_H\n struct object_list {\n \tstruct object *item;\n \tstruct object_list *next;\n-\tconst char *name;\n };\n \n struct object_refs {\n@@ -13,6 +12,15 @@ struct object_refs {\n \tstruct object *ref[FLEX_ARRAY]; /* more */\n };\n \n+struct object_array {\n+\tunsigned int nr;\n+\tunsigned int alloc;\n+\tstruct object_array_entry {\n+\t\tstruct object *item;\n+\t\tconst char *name;\n+\t} *objects;\n+};\n+\n #define TYPE_BITS   3\n #define FLAG_BITS  27\n \n@@ -72,4 +80,7 @@ unsigned object_list_length(struct objec\n \n int object_list_contains(struct object_list *list, struct object *obj);\n \n+/* Object array handling .. */\n+void add_object_array(struct object *obj, const char *name, struct object_array *array);\n+\n #endif /* OBJECT_H */\ndiff --git a/revision.c b/revision.c\nindex 7bff2a1..b963f2a 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -31,17 +31,12 @@ static char *path_name(struct name_path \n \treturn n;\n }\n \n-struct object_list **add_object(struct object *obj,\n-\t\t\t\t       struct object_list **p,\n-\t\t\t\t       struct name_path *path,\n-\t\t\t\t       const char *name)\n+void add_object(struct object *obj,\n+\t\tstruct object_array *p,\n+\t\tstruct name_path *path,\n+\t\tconst char *name)\n {\n-\tstruct object_list *entry = xmalloc(sizeof(*entry));\n-\tentry->item = obj;\n-\tentry->next = *p;\n-\tentry->name = path_name(path, name);\n-\t*p = entry;\n-\treturn &entry->next;\n+\tadd_object_array(obj, path_name(path, name), p);\n }\n \n static void mark_blob_uninteresting(struct blob *blob)\n@@ -117,9 +112,9 @@ void mark_parents_uninteresting(struct c\n \t}\n }\n \n-static void add_pending_object(struct rev_info *revs, struct object *obj, const char *name)\n+void add_pending_object(struct rev_info *revs, struct object *obj, const char *name)\n {\n-\tadd_object(obj, &revs->pending_objects, NULL, name);\n+\tadd_object_array(obj, name, &revs->pending);\n }\n \n static struct object *get_reference(struct rev_info *revs, const char *name, const unsigned char *sha1, unsigned int flags)\n@@ -836,7 +831,7 @@ int setup_revisions(int argc, const char\n \t\tobject = get_reference(revs, arg, sha1, flags ^ local_flags);\n \t\tadd_pending_object(revs, object, arg);\n \t}\n-\tif (def && !revs->pending_objects) {\n+\tif (def && !revs->pending.nr) {\n \t\tunsigned char sha1[20];\n \t\tstruct object *object;\n \t\tif (get_sha1(def, sha1))\n@@ -868,11 +863,13 @@ int setup_revisions(int argc, const char\n \n void prepare_revision_walk(struct rev_info *revs)\n {\n-\tstruct object_list *list;\n+\tint nr = revs->pending.nr;\n+\tstruct object_array_entry *list = revs->pending.objects;\n \n-\tlist = revs->pending_objects;\n-\trevs->pending_objects = NULL;\n-\twhile (list) {\n+\trevs->pending.nr = 0;\n+\trevs->pending.alloc = 0;\n+\trevs->pending.objects = NULL;\n+\twhile (--nr >= 0) {\n \t\tstruct commit *commit = handle_commit(revs, list->item, list->name);\n \t\tif (commit) {\n \t\t\tif (!(commit->object.flags & SEEN)) {\n@@ -880,7 +877,7 @@ void prepare_revision_walk(struct rev_in\n \t\t\t\tinsert_by_date(commit, &revs->commits);\n \t\t\t}\n \t\t}\n-\t\tlist = list->next;\n+\t\tlist++;\n \t}\n \n \tif (revs->no_walk)\ndiff --git a/revision.h b/revision.h\nindex 4020e25..c010a08 100644\n--- a/revision.h\n+++ b/revision.h\n@@ -18,7 +18,7 @@ typedef void (prune_fn_t)(struct rev_inf\n struct rev_info {\n \t/* Starting list */\n \tstruct commit_list *commits;\n-\tstruct object_list *pending_objects;\n+\tstruct object_array pending;\n \n \t/* Basic information */\n \tconst char *prefix;\n@@ -99,9 +99,11 @@ struct name_path {\n \tconst char *elem;\n };\n \n-extern struct object_list **add_object(struct object *obj,\n-\t\t\t\t       struct object_list **p,\n-\t\t\t\t       struct name_path *path,\n-\t\t\t\t       const char *name);\n+extern void add_object(struct object *obj,\n+\t\t       struct object_array *p,\n+\t\t       struct name_path *path,\n+\t\t       const char *name);\n+\n+extern void add_pending_object(struct rev_info *revs, struct object *obj, const char *name);\n \n #endif\n"}]}