git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rafael Silva <rafaeloliveira.cs@gmail.com>
To: Miriam Rubio <mirucam@gmail.com>
Cc: git@vger.kernel.org, Pranit Bauva <pranit.bauva@gmail.com>,
	Lars Schneider <larsxschneider@gmail.com>,
	Christian Couder <chriscool@tuxfamily.org>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	Tanushree Tumane <tanushreetumane@gmail.com>
Subject: Re: [PATCH v2 2/7] bisect--helper: reimplement `bisect_replay` shell function in C
Date: Wed, 23 Dec 2020 01:23:49 +0100	[thread overview]
Message-ID: <gohp6klfdpbca4.fsf@cpm12071.fritz.box> (raw)
In-Reply-To: <20201221162743.96056-3-mirucam@gmail.com>


Hi Miriam,

Miriam Rubio writes:

> +
> +static int process_replay_file(FILE *fp, struct bisect_terms *terms)
> +{
> +	struct strbuf line = STRBUF_INIT;
> +	struct strbuf word = STRBUF_INIT;
> +	int res = 0;
> +
> +	while (strbuf_getline(&line, fp) != EOF) {
> +		res = process_line(terms, &line, &word);
> +		if (res)
> +			break;
> +	}
> +

I spotted another place where an optimization can be performed.

The "if (res) .. break" conditional is only used to break the loop,
which is the same job of the expression from the while-loop
itself. Hence, as the purpose is to control the loop execution itself,
checking the response of "process_line()" via the "res" value can be
move to the loop expression itself and simplifying the code further,
as shown on the following patch:

-- >8 --

diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c
index b887413d8d..fb15587af8 100644
--- a/builtin/bisect--helper.c
+++ b/builtin/bisect--helper.c
@@ -988,11 +988,8 @@ static int process_replay_file(FILE *fp, struct bisect_terms *terms)
        struct strbuf word = STRBUF_INIT;
        int res = 0;

-       while (strbuf_getline(&line, fp) != EOF) {
+       while (!res && strbuf_getline(&line, fp) != EOF)
                res = process_line(terms, &line, &word);
-               if (res)
-                       break;
-       }

        strbuf_release(&line);
        strbuf_release(&word);

-- >8 --

This also seems to be similar approach from "one_of()" introduced by
4ba1e5c414 (bisect--helper: rewrite `check_term_format` shell function
in C, 2017-09-29).

Once more, the intention is to simplify the code and improve the code
maintainability.

> +	strbuf_release(&line);
> +	strbuf_release(&word);
> +	return res;
> +}
> +

I hope this helps increase the code quality.
Happy Holidays

-- 
Thanks
Rafael

  parent reply	other threads:[~2020-12-23  0:24 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-21 16:27 [PATCH v2 0/7] Finish converting git bisect to C part 3 Miriam Rubio
2020-12-21 16:27 ` [PATCH v2 1/7] bisect--helper: reimplement `bisect_log` shell function in C Miriam Rubio
2021-01-18 15:02   ` Johannes Schindelin
2020-12-21 16:27 ` [PATCH v2 2/7] bisect--helper: reimplement `bisect_replay` " Miriam Rubio
2020-12-22  0:15   ` Rafael Silva
2020-12-23  0:23   ` Rafael Silva [this message]
2020-12-23  1:36     ` Junio C Hamano
2020-12-23 10:03       ` Rafael Silva
2020-12-23 20:09         ` Junio C Hamano
2021-01-18 15:59   ` Johannes Schindelin
2020-12-21 16:27 ` [PATCH v2 3/7] bisect--helper: retire `--bisect-write` subcommand Miriam Rubio
2020-12-21 16:27 ` [PATCH v2 4/7] bisect--helper: use `res` instead of return in BISECT_RESET case option Miriam Rubio
2020-12-21 16:27 ` [PATCH v2 5/7] bisect--helper: retire `--bisect-auto-next` subcommand Miriam Rubio
2020-12-21 16:27 ` [PATCH v2 6/7] bisect--helper: reimplement `bisect_skip` shell function in C Miriam Rubio
2021-01-18 16:14   ` Johannes Schindelin
2020-12-21 16:27 ` [PATCH v2 7/7] bisect--helper: retire `--check-and-set-terms` subcommand Miriam Rubio
2021-01-18 16:15 ` [PATCH v2 0/7] Finish converting git bisect to C part 3 Johannes Schindelin
2021-01-18 23:53   ` Junio C Hamano

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=gohp6klfdpbca4.fsf@cpm12071.fritz.box \
    --to=rafaeloliveira.cs@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=chriscool@tuxfamily.org \
    --cc=git@vger.kernel.org \
    --cc=larsxschneider@gmail.com \
    --cc=mirucam@gmail.com \
    --cc=pranit.bauva@gmail.com \
    --cc=tanushreetumane@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;
as well as URLs for NNTP newsgroup(s).