Avoid a useless prefix lookup in strbuf_expand()
Currently, the --pretty=format prefix is looked up in a tight loop in strbuf_expand(), if prefix is found it is then used as argument for format_commit_item() that does another search by a switch statement to select the proper operation. Because the switch statement is already able to discard unknown matches we don't need the prefix lookup before to call format_commit_item(). Signed-off-by: Marco Costalba <mcostalba@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
053d9e432b
commit
c3a670de50
19
strbuf.c
19
strbuf.c
@ -146,11 +146,12 @@ void strbuf_addf(struct strbuf *sb, const char *fmt, ...)
|
||||
strbuf_setlen(sb, sb->len + len);
|
||||
}
|
||||
|
||||
void strbuf_expand(struct strbuf *sb, const char *format,
|
||||
const char **placeholders, expand_fn_t fn, void *context)
|
||||
void strbuf_expand(struct strbuf *sb, const char *format, expand_fn_t fn,
|
||||
void *context)
|
||||
{
|
||||
for (;;) {
|
||||
const char *percent, **p;
|
||||
const char *percent;
|
||||
size_t consumed;
|
||||
|
||||
percent = strchrnul(format, '%');
|
||||
strbuf_add(sb, format, percent - format);
|
||||
@ -158,14 +159,10 @@ void strbuf_expand(struct strbuf *sb, const char *format,
|
||||
break;
|
||||
format = percent + 1;
|
||||
|
||||
for (p = placeholders; *p; p++) {
|
||||
if (!prefixcmp(format, *p))
|
||||
break;
|
||||
}
|
||||
if (*p) {
|
||||
fn(sb, *p, context);
|
||||
format += strlen(*p);
|
||||
} else
|
||||
consumed = fn(sb, format, context);
|
||||
if (consumed)
|
||||
format += consumed;
|
||||
else
|
||||
strbuf_addch(sb, '%');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user