[PATCH v2 08/19] builtin/mailinfo: simplify via strbuf_set()
From: Jeremiah Mahler <hidden>
Date: 2016-06-15 23:01:33
Subsystem:
the rest · Maintainer:
Linus Torvalds
Simplify cases where a strbuf_reset is immediately followed by a strbuf_add by using strbuf_set operations. Signed-off-by: Jeremiah Mahler <redacted> --- builtin/mailinfo.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c
index cf11c8d..596071e 100644
--- a/builtin/mailinfo.c
+++ b/builtin/mailinfo.c@@ -40,8 +40,7 @@ static void get_sane_name(struct strbuf *out, struct strbuf *name, struct strbuf src = email; else if (name == out) return; - strbuf_reset(out); - strbuf_addbuf(out, src); + strbuf_setbuf(out, src); } static void parse_bogus_from(const struct strbuf *line)
@@ -62,11 +61,9 @@ static void parse_bogus_from(const struct strbuf *line) if (!ket) return; - strbuf_reset(&email); - strbuf_add(&email, bra + 1, ket - bra - 1); + strbuf_set(&email, bra + 1, ket - bra - 1); - strbuf_reset(&name); - strbuf_add(&name, line->buf, bra - line->buf); + strbuf_set(&name, line->buf, bra - line->buf); strbuf_trim(&name); get_sane_name(&name, &name, &email); }
@@ -108,8 +105,7 @@ static void handle_from(const struct strbuf *from) at--; } el = strcspn(at, " \n\t\r\v\f>"); - strbuf_reset(&email); - strbuf_add(&email, at, el); + strbuf_set(&email, at, el); strbuf_remove(&f, at - f.buf, el + (at[el] ? 1 : 0)); /* The remainder is name. It could be
@@ -567,8 +563,7 @@ static int decode_header_bq(struct strbuf *it) in = ep + 2; } strbuf_addstr(&outbuf, in); - strbuf_reset(it); - strbuf_addbuf(it, &outbuf); + strbuf_setbuf(it, &outbuf); decode_header_bq_out: strbuf_release(&outbuf); strbuf_release(&charset_q);
@@ -602,8 +597,7 @@ static void decode_transfer_encoding(struct strbuf *line) default: return; } - strbuf_reset(line); - strbuf_addbuf(line, ret); + strbuf_setbuf(line, ret); strbuf_release(ret); free(ret); }
--
2.0.0.592.gf55b190