From: Junio C Hamano <gitster@pobox.com>
To: 胡哲宁 <adlternative@gmail.com>
Cc: "阿德烈 via GitGitGadget" <gitgitgadget@gmail.com>,
"Git List" <git@vger.kernel.org>, "Jeff King" <peff@peff.net>
Subject: Re: [PATCH] strbuf.c: optimize program logic
Date: Tue, 26 Jan 2021 10:47:01 -0800 [thread overview]
Message-ID: <xmqq8s8f3596.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <CAOLTT8T1N2FSK3GiLaQUZt-OO5qzjQz7iq2cuKxasmuwnEZoXw@mail.gmail.com> ("胡哲宁"'s message of "Tue, 26 Jan 2021 18:44:57 +0800")
胡哲宁 <adlternative@gmail.com> writes:
> 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.
next prev parent reply other threads:[~2021-01-26 22:19 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-26 5:06 [PATCH] strbuf.c: optimize program logic 阿德烈 via GitGitGadget
2021-01-26 6:17 ` Junio C Hamano
2021-01-26 10:44 ` 胡哲宁
2021-01-26 18:47 ` Junio C Hamano [this message]
2021-01-26 18:23 ` Jeff King
2021-01-26 20:15 ` Junio C Hamano
2021-01-29 6:09 ` 胡哲宁
2021-01-30 8:50 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqq8s8f3596.fsf@gitster.c.googlers.com \
--to=gitster@pobox.com \
--cc=adlternative@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).