{"thread":{"id":"7680","subject":"[PATCH 1/9] pack-objects: optimize preferred base handling a bit","startedAt":"2007-04-16T16:14:50Z","lastAt":"2007-04-16T16:14:50Z","messageCount":1,"participants":["Nicolas Pitre"],"isPatch":true,"patchVersion":1,"patchTotal":9},"messages":[{"id":"39535","messageId":"S1030820AbXDPQOx/20070416161453Z+1494@vger.kernel.org","threadId":"7680","inReplyTo":null,"subject":"[PATCH 1/9] pack-objects: optimize preferred base handling a bit","fromName":"Nicolas Pitre","fromEmail":"nico@cam.org","sentAt":"2007-04-16T16:14:50Z","receivedAt":"2007-04-16T16:14:50Z","isPatch":true,"sender":{"key":"nico@fluxnic.net","avatar":"https://avatars.githubusercontent.com/u/702790?v=4"},"body":"Let's avoid some cycles when there is no base to test against, and avoid\nunnecessary object lookups.\n\nSigned-off-by: Nicolas Pitre <nico@cam.org>\n---\n builtin-pack-objects.c |   27 ++++++++++++---------------\n 1 files changed, 12 insertions(+), 15 deletions(-)\n\ndiff --git a/builtin-pack-objects.c b/builtin-pack-objects.c\nindex bc5f232..62a011e 100644\n--- a/builtin-pack-objects.c\n+++ b/builtin-pack-objects.c\n@@ -959,22 +959,21 @@ static void add_pbase_object(struct tree_desc *tree,\n \t\t\t     const char *fullname)\n {\n \tstruct name_entry entry;\n+\tint cmp;\n \n \twhile (tree_entry(tree,&entry)) {\n-\t\tunsigned long size;\n-\t\tenum object_type type;\n-\n-\t\tif (tree_entry_len(entry.path, entry.sha1) != cmplen ||\n-\t\t    memcmp(entry.path, name, cmplen) ||\n-\t\t    !has_sha1_file(entry.sha1) ||\n-\t\t    (type = sha1_object_info(entry.sha1, &size)) < 0)\n+\t\tcmp = tree_entry_len(entry.path, entry.sha1) != cmplen ? 1 :\n+\t\t      memcmp(name, entry.path, cmplen);\n+\t\tif (cmp > 0)\n \t\t\tcontinue;\n+\t\tif (cmp < 0)\n+\t\t\treturn;\n \t\tif (name[cmplen] != '/') {\n \t\t\tunsigned hash = name_hash(fullname);\n \t\t\tadd_object_entry(entry.sha1, hash, 1);\n \t\t\treturn;\n \t\t}\n-\t\tif (type == OBJ_TREE) {\n+\t\tif (S_ISDIR(entry.mode)) {\n \t\t\tstruct tree_desc sub;\n \t\t\tstruct pbase_tree_cache *tree;\n \t\t\tconst char *down = name+cmplen+1;\n@@ -1034,15 +1033,15 @@ static int check_pbase_path(unsigned hash)\n static void add_preferred_base_object(const char *name, unsigned hash)\n {\n \tstruct pbase_tree *it;\n-\tint cmplen = name_cmp_len(name);\n+\tint cmplen;\n \n-\tif (check_pbase_path(hash))\n+\tif (!num_preferred_base || check_pbase_path(hash))\n \t\treturn;\n \n+\tcmplen = name_cmp_len(name);\n \tfor (it = pbase_tree; it; it = it->next) {\n \t\tif (cmplen == 0) {\n-\t\t\thash = name_hash(\"\");\n-\t\t\tadd_object_entry(it->pcache.sha1, hash, 1);\n+\t\t\tadd_object_entry(it->pcache.sha1, 0, 1);\n \t\t}\n \t\telse {\n \t\t\tstruct tree_desc tree;\n@@ -1587,9 +1586,7 @@ static void read_object_list_from_stdin(void)\n \n static void show_commit(struct commit *commit)\n {\n-\tunsigned hash = name_hash(\"\");\n-\tadd_preferred_base_object(\"\", hash);\n-\tadd_object_entry(commit->object.sha1, hash, 0);\n+\tadd_object_entry(commit->object.sha1, 0, 0);\n }\n \n static void show_object(struct object_array_entry *p)\n-- \n1.5.1.1.781.g65e8\n"}]}