Thread (11 messages) flat view 11 messages, 5 authors, 2020-02-27

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

From: Johannes Sixt <hidden>
Date: 2020-02-19 08:13:56

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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help