[RFC PATCH v1 0/1] strbuf.c/h: add the constant version initialization method of strbuf
- From
ZheNing Hu <adlternative@gmail.com>
- Date
- Jan 5, 2021, 06:45 UTC
- Message-ID
- <20210105064502.725307-1-adlternative@gmail.com>
According to https://public-inbox.org/git/nycvar.QRO.7.76.6.1806210857520.11870@tvgsbejvaqbjf.bet/, we can create a new way to initialize strbuf with string constantto save the overhead of dynamically allocated memory.The marco function STRBUF_INIT_CONST(str).For example,STRBUF_ININ_DEFAULT("default") will create a strbuf which buf eqoal to "default", len eqoal to 7 and alloc eqoal to 0.This constant strbuf will be changed to dynamic allocation when we want to modify the contents of the constant buffer, The function strbuf_const_to_no_const do this by change buf with xstrdup,some function like strbuf_grow and strbuf_setlen will use it,to change the strbuf to a dynamically expand buffer.
My inference is based on an non-const strbuf with alloc greater than 0 and len greater than 0, const strbuf with alloc = 0 and len greater than 0. But now it have some bug because of I don't know where is the situation that non-const strbuf with 0 alloc and more then 0 len,this is a bit out of my expectation. So I fail check in gitgitgadget's check. Who can give me some advice?
Thanks.
ZheNing Hu (1): strbuf.c/h: add the constant version initialization method of strbuf
strbuf.c | 33 +++++++++++++++++++++++++++++---- strbuf.h | 8 ++++++++ 2 files changed, 37 insertions(+), 4 deletions(-)
-- 2.30.0