Skip to content

Commit d689d6d

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 15a4205 commit d689d6d

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

builtin/name-rev.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ static struct rev_name *get_commit_rev_name(const struct commit *commit)
3939
return slot ? *slot : NULL;
4040
}
4141

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-
4742
static int is_better_name(struct rev_name *name,
4843
timestamp_t taggerdate,
4944
int distance,
@@ -86,15 +81,14 @@ static struct rev_name *create_or_update_name(struct commit *commit,
8681
int generation, int distance,
8782
int from_tag)
8883
{
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;
9086

9187
if (name && !is_better_name(name, taggerdate, distance, from_tag))
9288
return NULL;
9389

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));
9892

9993
name->tip_name = tip_name;
10094
name->taggerdate = taggerdate;

0 commit comments

Comments
 (0)