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

Re: [PATCH 1/7] strbuf: add "include_delim" parameter to "strbuf_split"

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 13, 2009, 07:06 UTC
Message-ID
<7v7i2tj411.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<200903130702.01039.chriscool@tuxfamily.org>
Christian Couder <chriscool@tuxfamily.org> writes:
Show 7 quoted lines
>> Also comparing this with Perl/Python split() forgets that you are working
>> in C, where truncating an existing string is quite cheap (just assign
>> '\0'). There is a different trade-off to be made in these language
>> environments.
>
> Sorry but I think the goal of the strbuf API is to be quite high level, so I 
> think comparing this with Perl/Python is ok.
I think you are mistaken again.

The highlevel-ness of strbuf holds true only while you live in the strbuf world, but you should consider what happens when its end product finally gets used in the calling function written in C. It will be a good-old NUL terminated string or just a chunk of memory with known length.

For a user written in C, it is far easier and cheaper to trim excess at the end, especially when the length of the string is known (strbuf_detach gives you the length of the string exactly for this reason) than having to extend it (in order to recover the lost delimiter because the splitter removed it). Trimming from the front is also cheap (just move the head pointer and start consuming from the middle).

Previous: Johannes Schindelin
Message 9 of 9 in “strbuf: add "include_delim" parameter to "strbuf_split"”
  1. 1/7 strbuf: add "include_delim" parameter to "strbuf_split"Christian Couder, Mar 12, 2009
  2. Christian CouderMar 13, 2009
  3. Junio C HamanoMar 13, 2009
  4. Christian CouderMar 13, 2009
  5. Junio C HamanoMar 13, 2009
  6. Migrate bisect to C (was: [PATCH 1/7] strbuf: add "include_delim" parameter to "strbuf_split")Christian Couder, Mar 14, 2009
  7. Junio C HamanoMar 14, 2009
  8. fetch--tool, was Re: Migrate bisect to CJohannes Schindelin, Mar 14, 2009
  9. Junio C HamanoMar 13, 2009

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.