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

Re: [PATCH v4 5/8] trailer: clarify failure modes in parse_trailer

From
JTJonathan Tan <jonathantanmy@google.com>
Date
Oct 20, 2016, 22:40 UTC
Message-ID
<22e4b88b-5273-99c9-bcb3-0748c17a7229@google.com>
In-Reply-To
<xmqqvawmekhk.fsf@gitster.mtv.corp.google.com>
On 10/20/2016 03:14 PM, Junio C Hamano wrote:
Show 19 quoted lines
> Stefan Beller <sbeller@google.com> writes:
>
>>> +static int find_separator(const char *line)
>>> +{
>>> +       const char *c;
>>> +       for (c = line; ; c++) {
>>> +               if (!*c || *c == '\n')
>>> +                       return -1;
>>> +               if (*c == '=' || strchr(separators, *c))
>>> +                       return c - line;
>>> +       }
>>
>> I was about to suggest this function can be simplified and maybe
>> even inlined by the use of strspn or strcspn, but I think manual
>> processing of the string is fine, too, as it would not really be shorter.
>
> Hmm, I fear that iterating over a line one-byte-at-a-time and
> running strchr(separators, *c) on it for each byte has a performance
> implication over running a single call to strcspn(line, separators).

If we do that, there is also the necessity of creating a string that combines the separators and '=' (I guess '\n' is not necessary now, since all the lines are null terminated). I'm OK either way.

(We could cache that string, although I would think that if we did that, we might as well write the loop manually, like in this patch.)

Previous: Junio C HamanoNext: Junio C Hamano
Message 8 of 19 in “allow non-trailers and multiple-line trailers”
  1. 0/8 allow non-trailers and multiple-line trailersJonathan Tan, Oct 20, 2016
  2. 1/8 trailer: improve const correctnessJonathan Tan, Oct 20, 2016
  3. 2/8 trailer: use list.h for doubly-linked listJonathan Tan, Oct 20, 2016
  4. 6/8 trailer: allow non-trailers in trailer blockJonathan Tan, Oct 20, 2016
  5. 5/8 trailer: clarify failure modes in parse_trailerJonathan Tan, Oct 20, 2016
  6. Stefan BellerOct 20, 2016
  7. Junio C HamanoOct 20, 2016
  8. Jonathan TanOct 20, 2016
  9. Junio C HamanoOct 20, 2016
  10. Jonathan TanOct 20, 2016
  11. Junio C HamanoOct 21, 2016
  12. Christian CouderOct 22, 2016
  13. Junio C HamanoOct 22, 2016
  14. Christian CouderOct 22, 2016
  15. Jonathan TanOct 20, 2016
  16. 8/8 trailer: support values folded to multiple linesJonathan Tan, Oct 20, 2016
  17. 4/8 trailer: make args have their own structJonathan Tan, Oct 20, 2016
  18. 7/8 trailer: forbid leading whitespace in trailersJonathan Tan, Oct 20, 2016
  19. 3/8 trailer: streamline trailer item create and addJonathan Tan, Oct 20, 2016

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.