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

name-rev: don't _peek() in create_or_update_name()

Look up the commit slab slot for the commit once using commit_rev_name_at() and populate it in case it is empty, instead of checking for emptiness in a separate step using commit_rev_name_peek() via get_commit_rev_name(). Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Feb 4, 2020 at 22:20 UTC d689d6d82fae2f4f948bf1c232cb1fe158e3f319
1 file changed +4 -10
builtin/name-rev.c
+4 -10
@@ -39,11 +39,6 @@ static struct rev_name *get_commit_rev_name(const struct commit *commit)
39 return slot ? *slot : NULL;
40 }
41
42 -static void set_commit_rev_name(struct commit *commit, struct rev_name *name)
43 -{
44 - *commit_rev_name_at(&rev_names, commit) = name;
45 -}
46 -
42 static int is_better_name(struct rev_name *name,
43 timestamp_t taggerdate,
44 int distance,
@@ -86,15 +81,14 @@ static struct rev_name *create_or_update_name(struct commit *commit,
81 int generation, int distance,
82 int from_tag)
83 {
89 - struct rev_name *name = get_commit_rev_name(commit);
84 + struct rev_name **slot = commit_rev_name_at(&rev_names, commit);
85 + struct rev_name *name = *slot;
86
87 if (name && !is_better_name(name, taggerdate, distance, from_tag))
88 return NULL;
89
94 - if (name == NULL) {
95 - name = xmalloc(sizeof(*name));
96 - set_commit_rev_name(commit, name);
97 - }
90 + if (!name)
91 + name = *slot = xmalloc(sizeof(*name));
92
93 name->tip_name = tip_name;
94 name->taggerdate = taggerdate;