[PATCH] branch: reset instead of release a strbuf
- From
Stefan Beller <sbeller@google.com>
- Date
- Oct 3, 2017, 22:17 UTC
- Message-ID
- <20171003221740.26325-1-sbeller@google.com>
- In-Reply-To
- <20171003214646.GZ19555@aiede.mtv.corp.google.com>
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 <jrnieder@gmail.com> Signed-off-by: Stefan Beller <sbeller@google.com> --- builtin/branch.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/builtin/branch.c b/builtin/branch.c index b998e16d0c..71ed1c7036 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -217,7 +217,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds, if (!head_rev) die(_("Couldn't look up commit object for HEAD")); } - for (i = 0; i < argc; i++, strbuf_release(&bname)) { + for (i = 0; i < argc; i++, strbuf_reset(&bname)) { char *target = NULL; int flags = 0; @@ -282,8 +282,9 @@ static int delete_branches(int argc, const char **argv, int force, int kinds, } free(name); + strbuf_release(&bname); - return(ret); + return ret; } static int calc_maxwidth(struct ref_array *refs, int remote_bonus)
-- 2.14.0.rc0.3.g6c2e499285