mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
replace strbuf_expand() with strbuf_expand_step()
Avoid the overhead of passing context to a callback function of strbuf_expand() by using strbuf_expand_step() in a loop instead. It requires explicit handling of %% and unrecognized placeholders, but is simpler, more direct and avoids void pointers. 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
39dbd49b41
commit
6f1e2d5279
20
strbuf.c
20
strbuf.c
@@ -427,26 +427,6 @@ int strbuf_expand_step(struct strbuf *sb, const char **formatp)
|
||||
return 1;
|
||||
}
|
||||
|
||||
void strbuf_expand(struct strbuf *sb, const char *format, expand_fn_t fn,
|
||||
void *context)
|
||||
{
|
||||
while (strbuf_expand_step(sb, &format)) {
|
||||
size_t consumed;
|
||||
|
||||
if (*format == '%') {
|
||||
strbuf_addch(sb, '%');
|
||||
format++;
|
||||
continue;
|
||||
}
|
||||
|
||||
consumed = fn(sb, format, context);
|
||||
if (consumed)
|
||||
format += consumed;
|
||||
else
|
||||
strbuf_addch(sb, '%');
|
||||
}
|
||||
}
|
||||
|
||||
size_t strbuf_expand_literal_cb(struct strbuf *sb,
|
||||
const char *placeholder,
|
||||
void *context UNUSED)
|
||||
|
||||
Reference in New Issue
Block a user