replace strbuf_expand_dict_cb() with strbuf_expand_step()
Avoid the overhead of setting up a dictionary and passing it via strbuf_expand() to strbuf_expand_dict_cb() by using strbuf_expand_step() in a loop instead. It requires explicit handling of %% and unrecognized placeholders, but is more direct and simpler overall, and expands only on demand. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
44ccb337f1
commit
39dbd49b41
16
strbuf.c
16
strbuf.c
@ -468,22 +468,6 @@ size_t strbuf_expand_literal_cb(struct strbuf *sb,
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t strbuf_expand_dict_cb(struct strbuf *sb, const char *placeholder,
|
||||
void *context)
|
||||
{
|
||||
struct strbuf_expand_dict_entry *e = context;
|
||||
size_t len;
|
||||
|
||||
for (; e->placeholder && (len = strlen(e->placeholder)); e++) {
|
||||
if (!strncmp(placeholder, e->placeholder, len)) {
|
||||
if (e->value)
|
||||
strbuf_addstr(sb, e->value);
|
||||
return len;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void strbuf_addbuf_percentquote(struct strbuf *dst, const struct strbuf *src)
|
||||
{
|
||||
size_t i, len = src->len;
|
||||
|
||||
Reference in New Issue
Block a user