summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a08f23a)
raw | patch | inline | side by side (parent: a08f23a)
author | Pierre Habouzit <madcoder@debian.org> | |
Sun, 16 Sep 2007 08:19:01 +0000 (10:19 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 17 Sep 2007 00:30:04 +0000 (17:30 -0700) |
Careful profiling shows that we spend more time guessing what pattern
allocation will have, whereas we can delay it only at the point where
add_rfc2047 will be used and don't allocate huge memory area for the many
cases where it's not.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
allocation will have, whereas we can delay it only at the point where
add_rfc2047 will be used and don't allocate huge memory area for the many
cases where it's not.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
commit.c | patch | blob | history |
diff --git a/commit.c b/commit.c
index 13af93363e3dba43baf1d0a3ff2a2a3938fe5da7..85889f966457bf11004daa40c2cbe664baf96fb4 100644 (file)
--- a/commit.c
+++ b/commit.c
return;
needquote:
+ strbuf_grow(sb, len * 3 + strlen(encoding) + 100);
strbuf_addf(sb, "=?%s?q?", encoding);
for (i = last = 0; i < len; i++) {
unsigned ch = line[i] & 0xFF;
strbuf_addstr(sb, "?=");
}
-static unsigned long bound_rfc2047(unsigned long len, const char *encoding)
-{
- /* upper bound of q encoded string of length 'len' */
- unsigned long elen = strlen(encoding);
-
- return len * 3 + elen + 100;
-}
-
static void add_user_info(const char *what, enum cmit_fmt fmt, struct strbuf *sb,
const char *line, enum date_mode dmode,
const char *encoding)
@@ -560,8 +553,7 @@ static void add_user_info(const char *what, enum cmit_fmt fmt, struct strbuf *sb
add_rfc2047(sb, line, display_name_length, encoding);
strbuf_add(sb, name_tail, namelen - display_name_length);
strbuf_addch(sb, '\n');
- }
- else {
+ } else {
strbuf_addf(sb, "%s: %.*s%.*s\n", what,
(fmt == CMIT_FMT_FULLER) ? 4 : 0,
filler, namelen, line);
* FULLER shows both authors and dates.
*/
if (!memcmp(line, "author ", 7)) {
- unsigned long len = linelen;
- if (fmt == CMIT_FMT_EMAIL)
- len = bound_rfc2047(linelen, encoding);
- strbuf_grow(sb, len + 80);
+ strbuf_grow(sb, linelen + 80);
add_user_info("Author", fmt, sb, line + 7, dmode, encoding);
}
-
if (!memcmp(line, "committer ", 10) &&
(fmt == CMIT_FMT_FULL || fmt == CMIT_FMT_FULLER)) {
- unsigned long len = linelen;
- if (fmt == CMIT_FMT_EMAIL)
- len = bound_rfc2047(linelen, encoding);
- strbuf_grow(sb, len + 80);
+ strbuf_grow(sb, linelen + 80);
add_user_info("Commit", fmt, sb, line + 10, dmode, encoding);
}
}
int plain_non_ascii)
{
struct strbuf title;
- unsigned long len;
strbuf_init(&title, 80);
strbuf_add(&title, line, linelen);
}
- /* Enough slop for the MIME header and rfc2047 */
- len = bound_rfc2047(title.len, encoding) + 1000;
- if (subject)
- len += strlen(subject);
- if (after_subject)
- len += strlen(after_subject);
- if (encoding)
- len += strlen(encoding);
-
- strbuf_grow(sb, title.len + len);
+ strbuf_grow(sb, title.len + 1024);
if (subject) {
strbuf_addstr(sb, subject);
add_rfc2047(sb, title.buf, title.len, encoding);