summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorLibravatar René Scharfe <l.s.r@web.de>2020-02-04 22:20:42 +0100
committerLibravatar Junio C Hamano <gitster@pobox.com>2020-02-05 10:24:15 -0800
commitd689d6d82fae2f4f948bf1c232cb1fe158e3f319 (patch)
treef2187f4f2708db210664dc74ac9fb79c3b4bcfa4 /builtin
parentname-rev: don't leak path copy in name_ref() (diff)
downloadtgif-d689d6d82fae2f4f948bf1c232cb1fe158e3f319.tar.xz
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>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/name-rev.c14
1 files changed, 4 insertions, 10 deletions
diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index 3e22a0503e..41aed436ca 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -39,11 +39,6 @@ static struct rev_name *get_commit_rev_name(const struct commit *commit)
return slot ? *slot : NULL;
}
-static void set_commit_rev_name(struct commit *commit, struct rev_name *name)
-{
- *commit_rev_name_at(&rev_names, commit) = name;
-}
-
static int is_better_name(struct rev_name *name,
timestamp_t taggerdate,
int distance,
@@ -86,15 +81,14 @@ static struct rev_name *create_or_update_name(struct commit *commit,
int generation, int distance,
int from_tag)
{
- struct rev_name *name = get_commit_rev_name(commit);
+ struct rev_name **slot = commit_rev_name_at(&rev_names, commit);
+ struct rev_name *name = *slot;
if (name && !is_better_name(name, taggerdate, distance, from_tag))
return NULL;
- if (name == NULL) {
- name = xmalloc(sizeof(*name));
- set_commit_rev_name(commit, name);
- }
+ if (!name)
+ name = *slot = xmalloc(sizeof(*name));
name->tip_name = tip_name;
name->taggerdate = taggerdate;