{"thread":{"id":"4549","subject":"Move \"void *util\" from \"struct object\" into \"struct commit\"","startedAt":"2006-06-18T01:26:18Z","lastAt":"2006-06-18T01:26:18Z","messageCount":1,"participants":["Linus Torvalds"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"21983","messageId":"Pine.LNX.4.64.0606171815220.5498@g5.osdl.org","threadId":"4549","inReplyTo":null,"subject":"Move \"void *util\" from \"struct object\" into \"struct commit\"","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2006-06-18T01:26:18Z","receivedAt":"2006-06-18T01:26:18Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\nEvery single user actually wanted this only for commit objects, and we \nhave no reason to waste space on it for other object types. So just move \nthe structure member from the low-level \"struct object\" into the \"struct \ncommit\". \n\nThis leaves the commit object the same size, and removes one unnecessary \npointer from all other object allocations.\n\nThis shrinks memory usage (still at a fairly hefty half-gig, admittedly) \nof \"git-rev-list --all --objects\" on the mozilla repo by another 5% in my \ntests.\n\nSigned-off-by: Linus Torvalds <torvalds@osdl.org>\n---\n\nThis is on top of the previous memory usage shrinking patch, and won't \nactually work without it (although if wanted, you can start off with this \none with some trivial modifications - they are _barely_ interdependent, \nwith very little overlap) \n\n blame.c               |   48 ++++++++++++++++++++++++------------------------\n builtin-show-branch.c |   24 ++++++++++++------------\n commit.c              |    4 ++--\n commit.h              |    1 +\n name-rev.c            |   12 +++++++++---\n object.h              |    1 -\n 6 files changed, 48 insertions(+), 42 deletions(-)\n\ndiff --git a/blame.c b/blame.c\nindex 88bfec2..2dd70ee 100644\n--- a/blame.c\n+++ b/blame.c\n@@ -108,8 +108,8 @@ static struct patch *get_patch(struct co\n \txdemitconf_t xecfg;\n \tmmfile_t file_c, file_o;\n \txdemitcb_t ecb;\n-\tstruct util_info *info_c = (struct util_info *)commit->object.util;\n-\tstruct util_info *info_o = (struct util_info *)other->object.util;\n+\tstruct util_info *info_c = (struct util_info *)commit->util;\n+\tstruct util_info *info_o = (struct util_info *)other->util;\n \tstruct timeval tv_start, tv_end;\n \n \tget_blob(commit);\n@@ -195,7 +195,7 @@ static int get_blob_sha1_internal(const \n \n static void get_blob(struct commit *commit)\n {\n-\tstruct util_info *info = commit->object.util;\n+\tstruct util_info *info = commit->util;\n \tchar type[20];\n \n \tif (info->buf)\n@@ -221,8 +221,8 @@ #if DEBUG\n /* For debugging only */\n static void print_map(struct commit *cmit, struct commit *other)\n {\n-\tstruct util_info *util = cmit->object.util;\n-\tstruct util_info *util2 = other->object.util;\n+\tstruct util_info *util = cmit->util;\n+\tstruct util_info *util2 = other->util;\n \n \tint i;\n \tint max =\n@@ -257,8 +257,8 @@ #endif\n static void fill_line_map(struct commit *commit, struct commit *other,\n \t\t\t  struct patch *p)\n {\n-\tstruct util_info *util = commit->object.util;\n-\tstruct util_info *util2 = other->object.util;\n+\tstruct util_info *util = commit->util;\n+\tstruct util_info *util2 = other->util;\n \tint *map = util->line_map;\n \tint *map2 = util2->line_map;\n \tint cur_chunk = 0;\n@@ -320,14 +320,14 @@ static void fill_line_map(struct commit \n \n static int map_line(struct commit *commit, int line)\n {\n-\tstruct util_info *info = commit->object.util;\n+\tstruct util_info *info = commit->util;\n \tassert(line >= 0 && line < info->num_lines);\n \treturn info->line_map[line];\n }\n \n static struct util_info* get_util(struct commit *commit)\n {\n-\tstruct util_info *util = commit->object.util;\n+\tstruct util_info *util = commit->util;\n \n \tif (util)\n \t\treturn util;\n@@ -338,13 +338,13 @@ static struct util_info* get_util(struct\n \tutil->line_map = NULL;\n \tutil->num_lines = -1;\n \tutil->pathname = NULL;\n-\tcommit->object.util = util;\n+\tcommit->util = util;\n \treturn util;\n }\n \n static int fill_util_info(struct commit *commit)\n {\n-\tstruct util_info *util = commit->object.util;\n+\tstruct util_info *util = commit->util;\n \n \tassert(util);\n \tassert(util->pathname);\n@@ -357,7 +357,7 @@ static int fill_util_info(struct commit \n \n static void alloc_line_map(struct commit *commit)\n {\n-\tstruct util_info *util = commit->object.util;\n+\tstruct util_info *util = commit->util;\n \tint i;\n \n \tif (util->line_map)\n@@ -381,7 +381,7 @@ static void alloc_line_map(struct commit\n \n static void init_first_commit(struct commit* commit, const char* filename)\n {\n-\tstruct util_info* util = commit->object.util;\n+\tstruct util_info* util = commit->util;\n \tint i;\n \n \tutil->pathname = filename;\n@@ -390,7 +390,7 @@ static void init_first_commit(struct com\n \n \talloc_line_map(commit);\n \n-\tutil = commit->object.util;\n+\tutil = commit->util;\n \n \tfor (i = 0; i < util->num_lines; i++)\n \t\tutil->line_map[i] = i;\n@@ -411,7 +411,7 @@ static void process_commits(struct rev_i\n \tassert(commit);\n \tinit_first_commit(commit, path);\n \n-\tutil = commit->object.util;\n+\tutil = commit->util;\n \tnum_blame_lines = util->num_lines;\n \tblame_lines = xmalloc(sizeof(struct commit *) * num_blame_lines);\n \tblame_contents = util->buf;\n@@ -450,7 +450,7 @@ static void process_commits(struct rev_i\n \t\t\tcontinue;\n \n \t\talloc_line_map(commit);\n-\t\tutil = commit->object.util;\n+\t\tutil = commit->util;\n \n \t\tfor (parents = commit->parents;\n \t\t     parents != NULL; parents = parents->next) {\n@@ -510,7 +510,7 @@ static int compare_tree_path(struct rev_\n {\n \tint ret;\n \tconst char* paths[2];\n-\tstruct util_info* util = c2->object.util;\n+\tstruct util_info* util = c2->util;\n \tpaths[0] = util->pathname;\n \tpaths[1] = NULL;\n \n@@ -539,7 +539,7 @@ static int same_tree_as_empty_path(struc\n \n static const char* find_rename(struct commit* commit, struct commit* parent)\n {\n-\tstruct util_info* cutil = commit->object.util;\n+\tstruct util_info* cutil = commit->util;\n \tstruct diff_options diff_opts;\n \tconst char *paths[1];\n \tint i;\n@@ -583,7 +583,7 @@ static void simplify_commit(struct rev_i\n \t\treturn;\n \n \tif (!commit->parents) {\n-\t\tstruct util_info* util = commit->object.util;\n+\t\tstruct util_info* util = commit->util;\n \t\tif (!same_tree_as_empty_path(revs, commit->tree,\n \t\t\t\t\t     util->pathname))\n \t\t\tcommit->object.flags |= TREECHANGE;\n@@ -610,7 +610,7 @@ static void simplify_commit(struct rev_i\n \t\tcase REV_TREE_NEW:\n \t\t{\n \n-\t\t\tstruct util_info* util = commit->object.util;\n+\t\t\tstruct util_info* util = commit->util;\n \t\t\tif (revs->remove_empty_trees &&\n \t\t\t    same_tree_as_empty_path(revs, p->tree,\n \t\t\t\t\t\t    util->pathname)) {\n@@ -701,13 +701,13 @@ static const char* format_time(unsigned \n \n static void topo_setter(struct commit* c, void* data)\n {\n-\tstruct util_info* util = c->object.util;\n+\tstruct util_info* util = c->util;\n \tutil->topo_data = data;\n }\n \n static void* topo_getter(struct commit* c)\n {\n-\tstruct util_info* util = c->object.util;\n+\tstruct util_info* util = c->util;\n \treturn util->topo_data;\n }\n \n@@ -850,7 +850,7 @@ int main(int argc, const char **argv)\n \t\tstruct util_info* u;\n \t\tif (!c)\n \t\t\tc = initial;\n-\t\tu = c->object.util;\n+\t\tu = c->util;\n \n \t\tif (!found_rename && strcmp(filename, u->pathname))\n \t\t\tfound_rename = 1;\n@@ -868,7 +868,7 @@ int main(int argc, const char **argv)\n \t\tif (!c)\n \t\t\tc = initial;\n \n-\t\tu = c->object.util;\n+\t\tu = c->util;\n \t\tget_commit_info(c, &ci);\n \t\tfwrite(sha1_to_hex(c->object.sha1), sha1_len, 1, stdout);\n \t\tif(compability) {\ndiff --git a/builtin-show-branch.c b/builtin-show-branch.c\nindex cf9c071..09d8227 100644\n--- a/builtin-show-branch.c\n+++ b/builtin-show-branch.c\n@@ -51,9 +51,9 @@ struct commit_name {\n static void name_commit(struct commit *commit, const char *head_name, int nth)\n {\n \tstruct commit_name *name;\n-\tif (!commit->object.util)\n-\t\tcommit->object.util = xmalloc(sizeof(struct commit_name));\n-\tname = commit->object.util;\n+\tif (!commit->util)\n+\t\tcommit->util = xmalloc(sizeof(struct commit_name));\n+\tname = commit->util;\n \tname->head_name = head_name;\n \tname->generation = nth;\n }\n@@ -65,8 +65,8 @@ static void name_commit(struct commit *c\n  */\n static void name_parent(struct commit *commit, struct commit *parent)\n {\n-\tstruct commit_name *commit_name = commit->object.util;\n-\tstruct commit_name *parent_name = parent->object.util;\n+\tstruct commit_name *commit_name = commit->util;\n+\tstruct commit_name *parent_name = parent->util;\n \tif (!commit_name)\n \t\treturn;\n \tif (!parent_name ||\n@@ -80,12 +80,12 @@ static int name_first_parent_chain(struc\n \tint i = 0;\n \twhile (c) {\n \t\tstruct commit *p;\n-\t\tif (!c->object.util)\n+\t\tif (!c->util)\n \t\t\tbreak;\n \t\tif (!c->parents)\n \t\t\tbreak;\n \t\tp = c->parents->item;\n-\t\tif (!p->object.util) {\n+\t\tif (!p->util) {\n \t\t\tname_parent(c, p);\n \t\t\ti++;\n \t\t}\n@@ -106,7 +106,7 @@ static void name_commits(struct commit_l\n \t/* First give names to the given heads */\n \tfor (cl = list; cl; cl = cl->next) {\n \t\tc = cl->item;\n-\t\tif (c->object.util)\n+\t\tif (c->util)\n \t\t\tcontinue;\n \t\tfor (i = 0; i < num_rev; i++) {\n \t\t\tif (rev[i] == c) {\n@@ -132,9 +132,9 @@ static void name_commits(struct commit_l\n \t\t\tstruct commit_name *n;\n \t\t\tint nth;\n \t\t\tc = cl->item;\n-\t\t\tif (!c->object.util)\n+\t\t\tif (!c->util)\n \t\t\t\tcontinue;\n-\t\t\tn = c->object.util;\n+\t\t\tn = c->util;\n \t\t\tparents = c->parents;\n \t\t\tnth = 0;\n \t\t\twhile (parents) {\n@@ -142,7 +142,7 @@ static void name_commits(struct commit_l\n \t\t\t\tchar newname[1000], *en;\n \t\t\t\tparents = parents->next;\n \t\t\t\tnth++;\n-\t\t\t\tif (p->object.util)\n+\t\t\t\tif (p->util)\n \t\t\t\t\tcontinue;\n \t\t\t\ten = newname;\n \t\t\t\tswitch (n->generation) {\n@@ -257,7 +257,7 @@ static void join_revs(struct commit_list\n static void show_one_commit(struct commit *commit, int no_name)\n {\n \tchar pretty[256], *cp;\n-\tstruct commit_name *name = commit->object.util;\n+\tstruct commit_name *name = commit->util;\n \tif (commit->object.parsed)\n \t\tpretty_print_commit(CMIT_FMT_ONELINE, commit, ~0,\n \t\t\t\t    pretty, sizeof(pretty), 0, NULL, NULL);\ndiff --git a/commit.c b/commit.c\nindex 11fca55..5914200 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -711,12 +711,12 @@ int count_parents(struct commit * commit\n \n void topo_sort_default_setter(struct commit *c, void *data)\n {\n-\tc->object.util = data;\n+\tc->util = data;\n }\n \n void *topo_sort_default_getter(struct commit *c)\n {\n-\treturn c->object.util;\n+\treturn c->util;\n }\n \n /*\ndiff --git a/commit.h b/commit.h\nindex c9de167..7c9ca3f 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -11,6 +11,7 @@ struct commit_list {\n \n struct commit {\n \tstruct object object;\n+\tvoid *util;\n \tunsigned long date;\n \tstruct commit_list *parents;\n \tstruct tree *tree;\ndiff --git a/name-rev.c b/name-rev.c\nindex 1f0135f..c29b93e 100644\n--- a/name-rev.c\n+++ b/name-rev.c\n@@ -19,7 +19,7 @@ static void name_rev(struct commit *comm\n \t\tconst char *tip_name, int merge_traversals, int generation,\n \t\tint deref)\n {\n-\tstruct rev_name *name = (struct rev_name *)commit->object.util;\n+\tstruct rev_name *name = (struct rev_name *)commit->util;\n \tstruct commit_list *parents;\n \tint parent_number = 1;\n \n@@ -41,7 +41,7 @@ static void name_rev(struct commit *comm\n \n \tif (name == NULL) {\n \t\tname = xmalloc(sizeof(rev_name));\n-\t\tcommit->object.util = name;\n+\t\tcommit->util = name;\n \t\tgoto copy_data;\n \t} else if (name->merge_traversals > merge_traversals ||\n \t\t\t(name->merge_traversals == merge_traversals &&\n@@ -108,7 +108,13 @@ static int name_ref(const char *path, co\n static const char* get_rev_name(struct object *o)\n {\n \tstatic char buffer[1024];\n-\tstruct rev_name *n = (struct rev_name *)o->util;\n+\tstruct rev_name *n;\n+\tstruct commit *c;\n+\n+\tif (o->type != TYPE_COMMIT)\n+\t\treturn \"undefined\";\n+\tc = (struct commit *) o;\n+\tn = c->util;\n \tif (!n)\n \t\treturn \"undefined\";\n \ndiff --git a/object.h b/object.h\nindex a0762b6..f4ee2e5 100644\n--- a/object.h\n+++ b/object.h\n@@ -29,7 +29,6 @@ struct object {\n \tunsigned flags : FLAG_BITS;\n \tunsigned char sha1[20];\n \tstruct object_refs *refs;\n-\tvoid *util;\n };\n \n extern int track_object_refs;\n"}]}