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

Re: [PATCH] branch: reset instead of release a strbuf

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 4, 2017, 02:19 UTC
Message-ID
<xmqqvajvfydm.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20171003234919.qsr54ncmw6cihowi@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 21 quoted lines
>>  /**
>>   * Release a string buffer and the memory it used. You should not use the
>> - * string buffer after using this function, unless you initialize it again.
>> + * string buffer after using this function.
>>   */
>>  extern void strbuf_release(struct strbuf *);
>
> I think it's actually OK to use the string buffer after this function.
> It's just an empty string.
>
> Perhaps we should be more explicit: this releases any resources and
> resets to a pristine, empty state. I suspect strbuf_detach() probably
> should make the same claim.
>
> Earlier you mentioned:
>
>> It is still not advisable to call strbuf_release until done using a
>> strbuf because it is wasteful, so keep that part of the advice.
>
> Is this what you meant? If so, I think we should probably be more
> explicit in giving people a hint to use strbuf_reset() for efficiency.

Yes, "should not use" above is simply misleading. Either drop it altogether, or say something like

	If you find yourself reusing the same strbuf in a loop and
	calling strbuf_release() each iteration, you may want to
	consider if it makes more sense to use strbuf_reset()
	instead in each iteration and calling strbuf_release() at
	the end.
perhaps.
Previous: Jeff KingNext: Jonathan Nieder
Message 6 of 9 in “branch: reset instead of release a strbuf”
  1. branch: reset instead of release a strbufStefan Beller, Oct 3, 2017
  2. Jonathan NiederOct 3, 2017
  3. branch: reset instead of release a strbufStefan Beller, Oct 3, 2017
  4. Jonathan NiederOct 3, 2017
  5. Jeff KingOct 3, 2017
  6. Junio C HamanoOct 4, 2017
  7. strbuf doc: reuse after strbuf_release is fineJonathan Nieder, Oct 4, 2017
  8. Junio C HamanoOct 4, 2017
  9. Jeff KingOct 4, 2017

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.