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

Re: [PATCH] strbuf.c: optimize program logic

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 26, 2021, 18:47 UTC
Message-ID
<xmqq8s8f3596.fsf@gitster.c.googlers.com>
In-Reply-To
<CAOLTT8T1N2FSK3GiLaQUZt-OO5qzjQz7iq2cuKxasmuwnEZoXw@mail.gmail.com>
胡哲宁 <adlternative@gmail.com> writes:
Show 18 quoted lines
> Junio C Hamano <gitster@pobox.com> 于2021年1月26日周二 下午2:17写道:
>>
>> "阿德烈 via GitGitGadget" <gitgitgadget@gmail.com> writes:
>>
>> > From: ZheNing Hu <adlternative@gmail.com>
>> >
>> > the usage in strbuf.h tell us"Alloc is somehow a
>> > "private" member that should not be messed with.
>> > use `strbuf_avail()`instead."
>>
>> When we use the word "private", it generally means it is private to
>> the implementation of the API.  IOW, it is usually fine for the
>> implementation of the API (i.e. for strbuf API, what you see in
>> strbuf.c) to use private members.
>>
> Well, I just think most other functions in strbuf.c follow the use
> of `strbuf_avail()` instead of "sb->alloc-sb->len-1", and the
> "sb->alloc-sb->len-1" that appears in `strbuf_read()` is not so uniform.

I actually wouldn't have minded if this were sold as "code clean-up to use _avail() when we open-code in the implementation of strbuf API in codepaths that are not performance critical."

I am not sure about the _setlen() side of the thing. It is quite obvious what is going on in the original, and it falls into "when it is written one way that is good enough, replacing it with another that is not significantly better often ends up being mere code churn.", I would think.

Thanks.
Previous: 胡哲宁Next: Jeff King
Message 4 of 8 in “strbuf.c: optimize program logic”
  1. strbuf.c: optimize program logic阿德烈 via GitGitGadget, Jan 26, 2021
  2. Junio C HamanoJan 26, 2021
  3. 胡哲宁Jan 26, 2021
  4. Junio C HamanoJan 26, 2021
  5. Jeff KingJan 26, 2021
  6. Junio C HamanoJan 26, 2021
  7. 胡哲宁Jan 29, 2021
  8. Jeff KingJan 30, 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.