Skip to content

Commit a9155c5

Browse files
stefanbellergitster
authored andcommitted
branch: reset instead of release a strbuf
Our documentation advises to not re-use a strbuf, after strbuf_release has been called on it. Use the proper reset instead. Currently 'strbuf_release' releases and re-initializes the strbuf, so it is safe, but slow. 'strbuf_reset' only resets the internal length variable, such that this could also be accounted for as a micro-optimization. Reviewed-by: Jonathan Nieder <[email protected]> Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4010f1d commit a9155c5

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

builtin/branch.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
216216
if (!head_rev)
217217
die(_("Couldn't look up commit object for HEAD"));
218218
}
219-
for (i = 0; i < argc; i++, strbuf_release(&bname)) {
219+
for (i = 0; i < argc; i++, strbuf_reset(&bname)) {
220220
char *target = NULL;
221221
int flags = 0;
222222

@@ -281,8 +281,9 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
281281
}
282282

283283
free(name);
284+
strbuf_release(&bname);
284285

285-
return(ret);
286+
return ret;
286287
}
287288

288289
static int calc_maxwidth(struct ref_array *refs, int remote_bonus)

0 commit comments

Comments
 (0)