From: "ZheNing Hu via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Christian Couder" <christian.couder@gmail.com>,
"Hariom Verma" <hariom18599@gmail.com>,
"Bagas Sanjaya" <bagasdotme@gmail.com>,
"Jeff King" <peff@peff.net>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
"Eric Sunshine" <sunshine@sunshineco.com>,
"Philip Oakley" <philipoakley@iee.email>,
"ZheNing Hu" <adlternative@gmail.com>,
"ZheNing Hu" <adlternative@gmail.com>
Subject: [PATCH 2/8] [GSOC] ref-filter: merge two for loop in grab_person
Date: Tue, 17 Aug 2021 08:41:35 +0000 [thread overview]
Message-ID: <9ff78d17f3839acd24df5439fac74ba5064579c8.1629189701.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1021.git.1629189701.gitgitgadget@gmail.com>
From: ZheNing Hu <adlternative@gmail.com>
grab_person() uses string for atom type comparison, this is very
inefficient. After the introduction of atom_type, we can use
atom_type to represent the atom type.
So modify the parameter type of grab_person() to atom_type,
and take use of the characteristics of ATOM_AUTHOR ==
ATOM_AUTHORNAME - 1 == ATOM_AUTHOREMAIL - 2 ==
ATOM_AUTHORDATE - 3 to check which author atom type is.
ATOM_COMMITTER, ATOM_TAGGER are same too.
At the same time, merge the for loop which handles %(creator*) in
grab_person() into the previous for loop which handles %(author*),
%(committer*),%(tagger*). This can reduce unnecessary traversal
of the used_atom list.
Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Hariom Verma <hariom18599@gmail.com>
Signed-off-by: ZheNing Hu <adlternative@gmail.com>
---
ref-filter.c | 57 +++++++++++++++++-----------------------------------
1 file changed, 18 insertions(+), 39 deletions(-)
diff --git a/ref-filter.c b/ref-filter.c
index e38046ca141..592b8d9bd0a 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1275,63 +1275,42 @@ static void grab_date(const char *buf, struct atom_value *v, const char *atomnam
}
/* See grab_values */
-static void grab_person(const char *who, struct atom_value *val, int deref, void *buf)
+static void grab_person(enum atom_type type, struct atom_value *val, int deref, void *buf)
{
int i;
+ const char *who = valid_atom[type].name;
int wholen = strlen(who);
const char *wholine = NULL;
for (i = 0; i < used_atom_cnt; i++) {
const char *name = used_atom[i].name;
+ enum atom_type atom_type = used_atom[i].atom_type;
struct atom_value *v = &val[i];
if (!!deref != (*name == '*'))
continue;
if (deref)
name++;
- if (strncmp(who, name, wholen))
- continue;
- if (name[wholen] != 0 &&
- strcmp(name + wholen, "name") &&
- !starts_with(name + wholen, "email") &&
- !starts_with(name + wholen, "date"))
+ if ((atom_type < type || atom_type > type + 3) &&
+ /*
+ * For a tag or a commit object, if "creator" or "creatordate" is
+ * requested, do something special.
+ */
+ ((atom_type != ATOM_CREATOR && atom_type != ATOM_CREATORDATE) ||
+ ((atom_type == ATOM_CREATOR || atom_type == ATOM_CREATORDATE) &&
+ type != ATOM_TAGGER && type != ATOM_COMMITTER)))
continue;
if (!wholine)
wholine = find_wholine(who, wholen, buf);
if (!wholine)
return; /* no point looking for it */
- if (name[wholen] == 0)
+ if (atom_type == type || atom_type == ATOM_CREATOR)
v->s = copy_line(wholine);
- else if (!strcmp(name + wholen, "name"))
+ else if (atom_type == type + 1)
v->s = copy_name(wholine);
- else if (starts_with(name + wholen, "email"))
+ else if (atom_type == type + 2)
v->s = copy_email(wholine, &used_atom[i]);
- else if (starts_with(name + wholen, "date"))
- grab_date(wholine, v, name);
- }
-
- /*
- * For a tag or a commit object, if "creator" or "creatordate" is
- * requested, do something special.
- */
- if (strcmp(who, "tagger") && strcmp(who, "committer"))
- return; /* "author" for commit object is not wanted */
- if (!wholine)
- wholine = find_wholine(who, wholen, buf);
- if (!wholine)
- return;
- for (i = 0; i < used_atom_cnt; i++) {
- const char *name = used_atom[i].name;
- enum atom_type atom_type = used_atom[i].atom_type;
- struct atom_value *v = &val[i];
- if (!!deref != (*name == '*'))
- continue;
- if (deref)
- name++;
-
- if (atom_type == ATOM_CREATORDATE)
+ else if (atom_type == type + 3 || atom_type == ATOM_CREATORDATE)
grab_date(wholine, v, name);
- else if (atom_type == ATOM_CREATOR)
- v->s = copy_line(wholine);
}
}
@@ -1520,13 +1499,13 @@ static void grab_values(struct atom_value *val, int deref, struct object *obj, s
case OBJ_TAG:
grab_tag_values(val, deref, obj);
grab_sub_body_contents(val, deref, data);
- grab_person("tagger", val, deref, buf);
+ grab_person(ATOM_TAGGER, val, deref, buf);
break;
case OBJ_COMMIT:
grab_commit_values(val, deref, obj);
grab_sub_body_contents(val, deref, data);
- grab_person("author", val, deref, buf);
- grab_person("committer", val, deref, buf);
+ grab_person(ATOM_AUTHOR, val, deref, buf);
+ grab_person(ATOM_COMMITTER, val, deref, buf);
break;
case OBJ_TREE:
/* grab_tree_values(val, deref, obj, buf, sz); */
--
gitgitgadget
next prev parent reply other threads:[~2021-08-17 8:41 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-17 8:41 [PATCH 0/8] [GSOC] [RFC] ref-filter: code logic optimization ZheNing Hu via GitGitGadget
2021-08-17 8:41 ` [PATCH 1/8] [GSOC] ref-filter: remove grab_oid() function ZheNing Hu via GitGitGadget
2021-08-17 8:41 ` ZheNing Hu via GitGitGadget [this message]
2021-08-17 8:41 ` [PATCH 3/8] [GSOC] ref-filter: remove strlen from find_subpos ZheNing Hu via GitGitGadget
2021-08-17 8:41 ` [PATCH 4/8] [GSOC] ref-filter: introducing xstrvfmt_len() and xstrfmt_len() ZheNing Hu via GitGitGadget
2021-08-17 8:41 ` [PATCH 5/8] [GSOC] ref-filter: introduction ref_filter_slopbuf[1] ZheNing Hu via GitGitGadget
2021-08-17 8:41 ` [PATCH 6/8] [GSOC] ref-filter: add deref member to struct used_atom ZheNing Hu via GitGitGadget
2021-08-17 8:41 ` [PATCH 7/8] [GSOC] ref-filter: introduce symref_atom_parser() ZheNing Hu via GitGitGadget
2021-08-17 8:41 ` [PATCH 8/8] [GSOC] ref-filter: use switch/case instead of if/else ZheNing Hu via GitGitGadget
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9ff78d17f3839acd24df5439fac74ba5064579c8.1629189701.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=adlternative@gmail.com \
--cc=avarab@gmail.com \
--cc=bagasdotme@gmail.com \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=hariom18599@gmail.com \
--cc=peff@peff.net \
--cc=philipoakley@iee.email \
--cc=sunshine@sunshineco.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).