Git development
 help / color / mirror / Atom feed
From: "SZEDER Gábor" <szeder@ira.uka.de>
To: Junio C Hamano <gitster@pobox.com>
Cc: "Karthik Nayak" <karthik.188@gmail.com>,
	git@vger.kernel.org, "SZEDER Gábor" <szeder@ira.uka.de>
Subject: [PATCH] ref-filter: strip format option after a field name only once while parsing
Date: Sun,  2 Oct 2016 18:35:11 +0200	[thread overview]
Message-ID: <20161002163511.609-1-szeder@ira.uka.de> (raw)

When parse_ref_filter_atom() iterates over a list of valid atoms to
check that a field name is one of them, it has to strip the optional
colon-separated format option suffix that might follow the field name.
However, it does so inside the loop, i.e. it performs the exact same
stripping over and over again.

Move stripping the format option suffix out of that loop, so it's only
performed once for each parsed field name.

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---
 ref-filter.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/ref-filter.c b/ref-filter.c
index 9adbb8af3eaa..9a8f55e45a16 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -235,7 +235,7 @@ int parse_ref_filter_atom(const char *atom, const char *ep)
 {
 	const char *sp;
 	const char *arg;
-	int i, at;
+	int i, at, atom_len;
 
 	sp = atom;
 	if (*sp == '*' && sp < ep)
@@ -250,19 +250,19 @@ int parse_ref_filter_atom(const char *atom, const char *ep)
 			return i;
 	}
 
+	/*
+	 * If the atom name has a colon, strip it and everything after
+	 * it off - it specifies the format for this entry, and
+	 * shouldn't be used for checking against the valid_atom
+	 * table.
+	 */
+	arg = memchr(sp, ':', ep - sp);
+	atom_len = (arg ? arg : ep) - sp;
+
 	/* Is the atom a valid one? */
 	for (i = 0; i < ARRAY_SIZE(valid_atom); i++) {
 		int len = strlen(valid_atom[i].name);
-
-		/*
-		 * If the atom name has a colon, strip it and everything after
-		 * it off - it specifies the format for this entry, and
-		 * shouldn't be used for checking against the valid_atom
-		 * table.
-		 */
-		arg = memchr(sp, ':', ep - sp);
-		if (len == (arg ? arg : ep) - sp &&
-		    !memcmp(valid_atom[i].name, sp, len))
+		if (len == atom_len && !memcmp(valid_atom[i].name, sp, len))
 			break;
 	}
 
-- 
2.10.0.516.gccda3a9


                 reply	other threads:[~2016-10-02 16:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20161002163511.609-1-szeder@ira.uka.de \
    --to=szeder@ira.uka.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=karthik.188@gmail.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