@matheusbsbs / matheus-bagliano / commits / d3ff6f5501
Fork 0

Move "void *util" from "struct object" into "struct commit"

Every single user actually wanted this only for commit objects, and we have no reason to waste space on it for other object types. So just move the structure member from the low-level "struct object" into the "struct commit". This leaves the commit object the same size, and removes one unnecessary pointer from all other object allocations. This shrinks memory usage (still at a fairly hefty half-gig, admittedly) of "git-rev-list --all --objects" on the mozilla repo by another 5% in my tests. Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Linus Torvalds committed Jun 17, 2006 at 18:26 UTC d3ff6f55012c939740ce0982b24aeb6fba3c6e4f
6 files changed +48 -42
blame.c
+24 -24
@@ -110,8 +110,8 @@ static struct patch *get_patch(struct commit *commit, struct commit *other)
110 xdemitconf_t xecfg;
111 mmfile_t file_c, file_o;
112 xdemitcb_t ecb;
113 - struct util_info *info_c = (struct util_info *)commit->object.util;
114 - struct util_info *info_o = (struct util_info *)other->object.util;
113 + struct util_info *info_c = (struct util_info *)commit->util;
114 + struct util_info *info_o = (struct util_info *)other->util;
115 struct timeval tv_start, tv_end;
116
117 get_blob(commit);
@@ -197,7 +197,7 @@ static int get_blob_sha1_internal(const unsigned char *sha1, const char *base,
197
198 static void get_blob(struct commit *commit)
199 {
200 - struct util_info *info = commit->object.util;
200 + struct util_info *info = commit->util;
201 char type[20];
202
203 if (info->buf)
@@ -223,8 +223,8 @@ static void print_patch(struct patch *p)
223 /* For debugging only */
224 static void print_map(struct commit *cmit, struct commit *other)
225 {
226 - struct util_info *util = cmit->object.util;
227 - struct util_info *util2 = other->object.util;
226 + struct util_info *util = cmit->util;
227 + struct util_info *util2 = other->util;
228
229 int i;
230 int max =
@@ -259,8 +259,8 @@ static void print_map(struct commit *cmit, struct commit *other)
259 static void fill_line_map(struct commit *commit, struct commit *other,
260 struct patch *p)
261 {
262 - struct util_info *util = commit->object.util;
263 - struct util_info *util2 = other->object.util;
262 + struct util_info *util = commit->util;
263 + struct util_info *util2 = other->util;
264 int *map = util->line_map;
265 int *map2 = util2->line_map;
266 int cur_chunk = 0;
@@ -322,14 +322,14 @@ static void fill_line_map(struct commit *commit, struct commit *other,
322
323 static int map_line(struct commit *commit, int line)
324 {
325 - struct util_info *info = commit->object.util;
325 + struct util_info *info = commit->util;
326 assert(line >= 0 && line < info->num_lines);
327 return info->line_map[line];
328 }
329
330 static struct util_info* get_util(struct commit *commit)
331 {
332 - struct util_info *util = commit->object.util;
332 + struct util_info *util = commit->util;
333
334 if (util)
335 return util;
@@ -340,13 +340,13 @@ static struct util_info* get_util(struct commit *commit)
340 util->line_map = NULL;
341 util->num_lines = -1;
342 util->pathname = NULL;
343 - commit->object.util = util;
343 + commit->util = util;
344 return util;
345 }
346
347 static int fill_util_info(struct commit *commit)
348 {
349 - struct util_info *util = commit->object.util;
349 + struct util_info *util = commit->util;
350
351 assert(util);
352 assert(util->pathname);
@@ -359,7 +359,7 @@ static int fill_util_info(struct commit *commit)
359
360 static void alloc_line_map(struct commit *commit)
361 {
362 - struct util_info *util = commit->object.util;
362 + struct util_info *util = commit->util;
363 int i;
364
365 if (util->line_map)
@@ -383,7 +383,7 @@ static void alloc_line_map(struct commit *commit)
383
384 static void init_first_commit(struct commit* commit, const char* filename)
385 {
386 - struct util_info* util = commit->object.util;
386 + struct util_info* util = commit->util;
387 int i;
388
389 util->pathname = filename;
@@ -392,7 +392,7 @@ static void init_first_commit(struct commit* commit, const char* filename)
392
393 alloc_line_map(commit);
394
395 - util = commit->object.util;
395 + util = commit->util;
396
397 for (i = 0; i < util->num_lines; i++)
398 util->line_map[i] = i;
@@ -413,7 +413,7 @@ static void process_commits(struct rev_info *rev, const char *path,
413 assert(commit);
414 init_first_commit(commit, path);
415
416 - util = commit->object.util;
416 + util = commit->util;
417 num_blame_lines = util->num_lines;
418 blame_lines = xmalloc(sizeof(struct commit *) * num_blame_lines);
419 blame_contents = util->buf;
@@ -452,7 +452,7 @@ static void process_commits(struct rev_info *rev, const char *path,
452 continue;
453
454 alloc_line_map(commit);
455 - util = commit->object.util;
455 + util = commit->util;
456
457 for (parents = commit->parents;
458 parents != NULL; parents = parents->next) {
@@ -512,7 +512,7 @@ static int compare_tree_path(struct rev_info* revs,
512 {
513 int ret;
514 const char* paths[2];
515 - struct util_info* util = c2->object.util;
515 + struct util_info* util = c2->util;
516 paths[0] = util->pathname;
517 paths[1] = NULL;
518
@@ -541,7 +541,7 @@ static int same_tree_as_empty_path(struct rev_info *revs, struct tree* t1,
541
542 static const char* find_rename(struct commit* commit, struct commit* parent)
543 {
544 - struct util_info* cutil = commit->object.util;
544 + struct util_info* cutil = commit->util;
545 struct diff_options diff_opts;
546 const char *paths[1];
547 int i;
@@ -585,7 +585,7 @@ static void simplify_commit(struct rev_info *revs, struct commit *commit)
585 return;
586
587 if (!commit->parents) {
588 - struct util_info* util = commit->object.util;
588 + struct util_info* util = commit->util;
589 if (!same_tree_as_empty_path(revs, commit->tree,
590 util->pathname))
591 commit->object.flags |= TREECHANGE;
@@ -612,7 +612,7 @@ static void simplify_commit(struct rev_info *revs, struct commit *commit)
612 case REV_TREE_NEW:
613 {
614
615 - struct util_info* util = commit->object.util;
615 + struct util_info* util = commit->util;
616 if (revs->remove_empty_trees &&
617 same_tree_as_empty_path(revs, p->tree,
618 util->pathname)) {
@@ -709,13 +709,13 @@ static const char* format_time(unsigned long time, const char* tz_str,
709
710 static void topo_setter(struct commit* c, void* data)
711 {
712 - struct util_info* util = c->object.util;
712 + struct util_info* util = c->util;
713 util->topo_data = data;
714 }
715
716 static void* topo_getter(struct commit* c)
717 {
718 - struct util_info* util = c->object.util;
718 + struct util_info* util = c->util;
719 return util->topo_data;
720 }
721
@@ -863,7 +863,7 @@ int main(int argc, const char **argv)
863 struct util_info* u;
864 if (!c)
865 c = initial;
866 - u = c->object.util;
866 + u = c->util;
867
868 if (!found_rename && strcmp(filename, u->pathname))
869 found_rename = 1;
@@ -881,7 +881,7 @@ int main(int argc, const char **argv)
881 if (!c)
882 c = initial;
883
884 - u = c->object.util;
884 + u = c->util;
885 get_commit_info(c, &ci);
886 fwrite(sha1_to_hex(c->object.sha1), sha1_len, 1, stdout);
887 if(compability) {
builtin-show-branch.c
+12 -12
@@ -51,9 +51,9 @@ struct commit_name {
51 static void name_commit(struct commit *commit, const char *head_name, int nth)
52 {
53 struct commit_name *name;
54 - if (!commit->object.util)
55 - commit->object.util = xmalloc(sizeof(struct commit_name));
56 - name = commit->object.util;
54 + if (!commit->util)
55 + commit->util = xmalloc(sizeof(struct commit_name));
56 + name = commit->util;
57 name->head_name = head_name;
58 name->generation = nth;
59 }
@@ -65,8 +65,8 @@ static void name_commit(struct commit *commit, const char *head_name, int nth)
65 */
66 static void name_parent(struct commit *commit, struct commit *parent)
67 {
68 - struct commit_name *commit_name = commit->object.util;
69 - struct commit_name *parent_name = parent->object.util;
68 + struct commit_name *commit_name = commit->util;
69 + struct commit_name *parent_name = parent->util;
70 if (!commit_name)
71 return;
72 if (!parent_name ||
@@ -80,12 +80,12 @@ static int name_first_parent_chain(struct commit *c)
80 int i = 0;
81 while (c) {
82 struct commit *p;
83 - if (!c->object.util)
83 + if (!c->util)
84 break;
85 if (!c->parents)
86 break;
87 p = c->parents->item;
88 - if (!p->object.util) {
88 + if (!p->util) {
89 name_parent(c, p);
90 i++;
91 }
@@ -106,7 +106,7 @@ static void name_commits(struct commit_list *list,
106 /* First give names to the given heads */
107 for (cl = list; cl; cl = cl->next) {
108 c = cl->item;
109 - if (c->object.util)
109 + if (c->util)
110 continue;
111 for (i = 0; i < num_rev; i++) {
112 if (rev[i] == c) {
@@ -132,9 +132,9 @@ static void name_commits(struct commit_list *list,
132 struct commit_name *n;
133 int nth;
134 c = cl->item;
135 - if (!c->object.util)
135 + if (!c->util)
136 continue;
137 - n = c->object.util;
137 + n = c->util;
138 parents = c->parents;
139 nth = 0;
140 while (parents) {
@@ -142,7 +142,7 @@ static void name_commits(struct commit_list *list,
142 char newname[1000], *en;
143 parents = parents->next;
144 nth++;
145 - if (p->object.util)
145 + if (p->util)
146 continue;
147 en = newname;
148 switch (n->generation) {
@@ -257,7 +257,7 @@ static void join_revs(struct commit_list **list_p,
257 static void show_one_commit(struct commit *commit, int no_name)
258 {
259 char pretty[256], *cp;
260 - struct commit_name *name = commit->object.util;
260 + struct commit_name *name = commit->util;
261 if (commit->object.parsed)
262 pretty_print_commit(CMIT_FMT_ONELINE, commit, ~0,
263 pretty, sizeof(pretty), 0, NULL, NULL);
commit.c
+2 -2
@@ -711,12 +711,12 @@ int count_parents(struct commit * commit)
711
712 void topo_sort_default_setter(struct commit *c, void *data)
713 {
714 - c->object.util = data;
714 + c->util = data;
715 }
716
717 void *topo_sort_default_getter(struct commit *c)
718 {
719 - return c->object.util;
719 + return c->util;
720 }
721
722 /*
commit.h
+1
@@ -11,6 +11,7 @@ struct commit_list {
11
12 struct commit {
13 struct object object;
14 + void *util;
15 unsigned long date;
16 struct commit_list *parents;
17 struct tree *tree;
name-rev.c
+9 -3
@@ -19,7 +19,7 @@ static void name_rev(struct commit *commit,
19 const char *tip_name, int merge_traversals, int generation,
20 int deref)
21 {
22 - struct rev_name *name = (struct rev_name *)commit->object.util;
22 + struct rev_name *name = (struct rev_name *)commit->util;
23 struct commit_list *parents;
24 int parent_number = 1;
25
@@ -41,7 +41,7 @@ static void name_rev(struct commit *commit,
41
42 if (name == NULL) {
43 name = xmalloc(sizeof(rev_name));
44 - commit->object.util = name;
44 + commit->util = name;
45 goto copy_data;
46 } else if (name->merge_traversals > merge_traversals ||
47 (name->merge_traversals == merge_traversals &&
@@ -108,7 +108,13 @@ static int name_ref(const char *path, const unsigned char *sha1)
108 static const char* get_rev_name(struct object *o)
109 {
110 static char buffer[1024];
111 - struct rev_name *n = (struct rev_name *)o->util;
111 + struct rev_name *n;
112 + struct commit *c;
113 +
114 + if (o->type != TYPE_COMMIT)
115 + return "undefined";
116 + c = (struct commit *) o;
117 + n = c->util;
118 if (!n)
119 return "undefined";
120
object.h
-1
@@ -29,7 +29,6 @@ struct object {
29 unsigned flags : FLAG_BITS;
30 unsigned char sha1[20];
31 struct object_refs *refs;
32 - void *util;
32 };
33
34 extern int track_object_refs;