From: Johannes Sixt Date: Wed, 19 Feb 2020 08:13:49 GMT Subject: Re: [GSoC][RFC][PATCH 1/2] STRBUF_INIT_CONST: a new way to initialize strbuf 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: > 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