notes.c: cleanup 'strbuf_grow' call in 'append_edit'
commitef48fcc432610bc2215c256cfddde7a14a0d2af2
authorTeng Long <dyroneteng@gmail.com>
Sat, 27 May 2023 07:57:48 +0000 (27 15:57 +0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 21 Jun 2023 15:51:00 +0000 (21 08:51 -0700)
tree37088385542adf97febdb028a580ec4ac69b6b31
parent7580f92ffa970b9484ac214f7b53cec5e26ca4bc
notes.c: cleanup 'strbuf_grow' call in 'append_edit'

Let's cleanup the unnecessary 'strbuf_grow' call in 'append_edit'. This
"strbuf_grow(&d.buf, size + 1);" is prepared for insert a blank line if
needed, but actually when inserting, "strbuf_insertstr(&d.buf, 0,
"\n");" will do the "grow" for us.

348f199b (builtin-notes: Refactor handling of -F option to allow
combining -m and -F, 2010-02-13) added these to mimic the code
introduced by 2347fae5 (builtin-notes: Add "append" subcommand for
appending to note objects, 2010-02-13) that reads in previous note
before the message.  And the resulting code with explicit sizing is
carried to this day.

In the context of reading an existing note in, exact sizing may have
made sense, but because the resulting note needs cleansing with
stripspace() when appending with this option, such an exact sizing
does not buy us all that much in practice.

It may help avoiding overallocation due to ALLOC_GROW() slop, but
nobody can feed so many long messages for it to matter from the
command line.

Signed-off-by: Teng Long <dyroneteng@gmail.com>
Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/notes.c