From d689d6d82fae2f4f948bf1c232cb1fe158e3f319 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Tue, 4 Feb 2020 22:20:42 +0100 Subject: [PATCH] name-rev: don't _peek() in create_or_update_name() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Junio C Hamano --- builtin/name-rev.c | 14 ++++---------- 1 file 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;