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

[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
Next: ZheNing Hu
Message 1 of 3 in “strbuf.c/h: add the constant version initialization method of strbuf”
  1. 0/1 strbuf.c/h: add the constant version initialization method of strbufZheNing Hu, Jan 5, 2021
  2. 1/1 strbuf.c/h: add the constant version initialization method of strbufZheNing Hu, Jan 5, 2021
  3. Eric SunshineJan 7, 2021

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.