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

Re: [GSoC][RFC][PATCH 1/2] STRBUF_INIT_CONST: a new way to initialize strbuf

From
Johannes Sixt <j6t@kdbg.org>
Date
Feb 19, 2020, 08:13 UTC
Message-ID
<467c035f-c7cd-01e1-e64c-2c915610de01@kdbg.org>
In-Reply-To
<20200218041805.10939-2-robear.selwans@outlook.com>
Am 18.02.20 um 05:18 schrieb Robear Selwans:
Show 18 quoted lines
> A new function `STRBUF_INIT_CONST(const_str)` was added to allow for a
> quick initialization of strbuf.
> 
> Details:
> Using `STRBUF_INIT_CONST(str)` creates a new struct of type `strbuf` and
> initializes its `buf`, `len` and `alloc` as `str`, `strlen(str)` and
> `0`, respectively.
> 
> Use Case:
> This is meant to be used to initialize strbufs with constant values and
> thus, only allocating memory when needed.
> 
> Usage Example:
> ```
> strbuf env_var = STRBUF_INIT_CONST("dev");
> ```
> 
> This was added according to the issue opened at [https://github.com/gitgitgadget/git/issues/398]

I am not a friend of this change at all. Why do so many functions and strbuf instances have to pay a price (check for immutable string) for a feature that they are not using?

As the macro is just intended for convenience, I suggest to implement it using strbuf_addstr() under the hood. That is much less code churn, and the price is paid only by the strbufs that actually use the feature.

-- Hannes
Previous: Jeff KingNext: René Scharfe
Message 6 of 11 in “STRBUF_INIT_CONST Cover”
  1. Robear SelwansFeb 18, 2020
  2. [GSoC][RFC][PATCH 1/2] STRBUF_INIT_CONST: a new way to initialize strbufRobear Selwans, Feb 18, 2020
  3. Jeff KingFeb 18, 2020
  4. Robear SelwansFeb 18, 2020
  5. Jeff KingFeb 18, 2020
  6. Johannes SixtFeb 19, 2020
  7. René ScharfeFeb 20, 2020
  8. Robear SelwansFeb 21, 2020
  9. Derrick StoleeFeb 27, 2020
  10. René ScharfeFeb 27, 2020
  11. [GSoC][RFC][PATCH 2/2] STRBUF_INIT_CONST: Adapting strbuf_* functionsRobear Selwans, Feb 18, 2020

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.