Skip to content

Commit ef48fcc

Browse files
dyronegitster
authored andcommitted
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. 348f199 (builtin-notes: Refactor handling of -F option to allow combining -m and -F, 2010-02-13) added these to mimic the code introduced by 2347fae (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 <[email protected]> Helped-by: Eric Sunshine <[email protected]> Helped-by: Junio C Hamano <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7580f92 commit ef48fcc

File tree

1 file changed

+0
-2
lines changed

1 file changed

+0
-2
lines changed

builtin/notes.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ static int parse_msg_arg(const struct option *opt, const char *arg, int unset)
219219

220220
BUG_ON_OPT_NEG(unset);
221221

222-
strbuf_grow(&d->buf, strlen(arg) + 2);
223222
if (d->buf.len)
224223
strbuf_addch(&d->buf, '\n');
225224
strbuf_addstr(&d->buf, arg);
@@ -623,7 +622,6 @@ static int append_edit(int argc, const char **argv, const char *prefix)
623622
char *prev_buf = repo_read_object_file(the_repository, note,
624623
&type, &size);
625624

626-
strbuf_grow(&d.buf, size + 1);
627625
if (d.buf.len && prev_buf && size)
628626
strbuf_insertstr(&d.buf, 0, "\n");
629627
if (prev_buf && size)

0 commit comments

Comments
 (0)