Thread (1 message) 1 message, 1 author, 2016-06-15

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

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:46:23

Christian Couder [off-list ref] writes:
quoted
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).
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help