OSDN Git Service

branch: reset instead of release a strbuf
authorStefan Beller <sbeller@google.com>
Tue, 3 Oct 2017 22:17:40 +0000 (15:17 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 4 Oct 2017 06:21:31 +0000 (15:21 +0900)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/branch.c

index 16d391b..2ea92a7 100644 (file)
@@ -216,7 +216,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;
 
@@ -281,8 +281,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)