wrap_in_html(): use strbuf_addstr_xml_quoted()
Use the new function to quote characters as they are being added to buf, rather than quoting them in *p and then copying them into buf. This increases code sharing, and changes the algorithm from O(N^2) to O(N) in the number of characters in a line. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Nov 25, 2012 at 12:08 UTC
3c64063558d57735384d3c547c0138aca7dfd3b8
1 file changed
+4
-19
imap-send.c
+4
-19
@@ -1339,21 +1339,6 @@ static int imap_store_msg(struct store *gctx, struct msg_data *msg)
1339
return DRV_OK;
1340
}
1341
1342
-static void encode_html_chars(struct strbuf *p)
1343
-{
1344
- int i;
1345
- for (i = 0; i < p->len; i++) {
1346
- if (p->buf[i] == '&')
1347
- strbuf_splice(p, i, 1, "&", 5);
1348
- if (p->buf[i] == '<')
1349
- strbuf_splice(p, i, 1, "<", 4);
1350
- if (p->buf[i] == '>')
1351
- strbuf_splice(p, i, 1, ">", 4);
1352
- if (p->buf[i] == '"')
1353
- strbuf_splice(p, i, 1, """, 6);
1354
- }
1355
-}
1356
-
1342
static void wrap_in_html(struct strbuf *msg)
1343
{
1344
struct strbuf buf = STRBUF_INIT;
@@ -1372,12 +1357,12 @@ static void wrap_in_html(struct strbuf *msg)
1357
strbuf_addbuf(&buf, *p);
1358
strbuf_addstr(&buf, pre_open);
1359
added_header = 1;
1375
- continue;
1360
+ } else {
1361
+ strbuf_addbuf(&buf, *p);
1362
}
1363
+ } else {
1364
+ strbuf_addstr_xml_quoted(&buf, (*p)->buf);
1365
}
1378
- else
1379
- encode_html_chars(*p);
1380
- strbuf_addbuf(&buf, *p);
1366
}
1367
strbuf_addstr(&buf, pre_close);
1368
strbuf_list_free(lines);