diff options
author | René Scharfe <l.s.r@web.de> | 2019-09-18 18:35:38 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2019-09-18 11:19:06 -0700 |
commit | 4b3aa170d14279aaf40db95bf3d93d43099e9614 (patch) | |
tree | 3d6097d4649b7102965c2ecc1c167459756f98fc /sha1-name.c | |
parent | 5fa0f5238b0cd46cfe7f6fa76c3f526ea98148d9 (diff) | |
download | git-4b3aa170d14279aaf40db95bf3d93d43099e9614.tar.gz |
sha1_name: simplify strbuf handling in interpret_nth_prior_checkout()
Pass the target strbuf to the callback function grab_nth_branch_switch()
by reference so that it can add the result string directly instead of
having it put the string into a temporary strbuf first. This gets rid
of an extra allocation and a string copy.
Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1-name.c')
-rw-r--r-- | sha1-name.c | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/sha1-name.c b/sha1-name.c index 2989e27b71..3c9e70baba 100644 --- a/sha1-name.c +++ b/sha1-name.c @@ -1289,7 +1289,7 @@ static int get_oid_oneline(struct repository *r, struct grab_nth_branch_switch_cbdata { int remaining; - struct strbuf buf; + struct strbuf *sb; }; static int grab_nth_branch_switch(struct object_id *ooid, struct object_id *noid, @@ -1307,8 +1307,8 @@ static int grab_nth_branch_switch(struct object_id *ooid, struct object_id *noid return 0; if (--(cb->remaining) == 0) { len = target - match; - strbuf_reset(&cb->buf); - strbuf_add(&cb->buf, match, len); + strbuf_reset(cb->sb); + strbuf_add(cb->sb, match, len); return 1; /* we are done */ } return 0; @@ -1341,18 +1341,15 @@ static int interpret_nth_prior_checkout(struct repository *r, if (nth <= 0) return -1; cb.remaining = nth; - strbuf_init(&cb.buf, 20); + cb.sb = buf; retval = refs_for_each_reflog_ent_reverse(get_main_ref_store(r), "HEAD", grab_nth_branch_switch, &cb); if (0 < retval) { - strbuf_reset(buf); - strbuf_addbuf(buf, &cb.buf); retval = brace - name + 1; } else retval = 0; - strbuf_release(&cb.buf); return retval; } |