git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] sequencer: clarify intention to break out of loop

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Oct 28, 2018, 19:01 UTC
Message-ID
<CAPig+cR28OBA0rwy=X6XU0cjstAguvUiLU9Zxjvg2X7=UsB5qw@mail.gmail.com>
In-Reply-To
<20181028153145.25734-1-martin.agren@gmail.com>
On Sun, Oct 28, 2018 at 11:32 AM Martin Ågren <martin.agren@gmail.com> wrote:
> [...]
> Let's be explicit about breaking out of the loop. This helps the
> compiler grok our intention. As a bonus, it might make it (even) more
> obvious to human readers that the loop stops at the first space.

This did come up in review[1,2]. I had a hard time understanding the loop because it looked idiomatic but wasn't (and we have preconceived notions about behavior of things which look idiomatic).

[1]: https://public-inbox.org/git/CAPig+cQbG2s-LrAo9+7C7=dXifbWFJ3SzuNa-QePHDk7egK=jg@mail.gmail.com/ [2]: https://public-inbox.org/git/CAPig+cRjU6niXpT2FrDWZ0x1HmGf1ojVZj3uk2qXEGe-S7i_HQ@mail.gmail.com/

Show 12 quoted lines
> Signed-off-by: Martin Ågren <martin.agren@gmail.com>
> ---
> diff --git a/sequencer.c b/sequencer.c
> @@ -2849,10 +2849,14 @@ static int do_reset(const char *name, int len, struct replay_opts *opts)
>                 /* Determine the length of the label */
> +               for (i = 0; i < len; i++) {
> +                       if (isspace(name[i])) {
>                                 len = i;
> +                               break;
> +                       }
> +               }
>                 strbuf_addf(&ref_name, "refs/rewritten/%.*s", len, name);
At least for me, this would be more idiomatic if it was coded like this:
    for (i = 0; i < len; i++)
        if (isspace(name[i]))
            break;
    strbuf_addf(..., i, name);
or, perhaps (less concise):
    for (i = 0; i < len; i++)
        if (isspace(name[i]))
            break;
    len = i;
    strbuf_addf(..., len, name);
Previous: Martin ÅgrenNext: Martin Ågren
Message 2 of 8 in “sequencer: clarify intention to break out of loop”
  1. sequencer: clarify intention to break out of loopMartin Ågren, Oct 28, 2018
  2. Eric SunshineOct 28, 2018
  3. Martin ÅgrenOct 28, 2018
  4. Junio C HamanoOct 29, 2018
  5. sequencer: break out of loop explicitlyMartin Ågren, Oct 30, 2018
  6. Johannes SchindelinOct 31, 2018
  7. Eric SunshineOct 31, 2018
  8. Martin ÅgrenOct 31, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.