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:
René Scharfe
2023-06-17 22:42:26 +02:00
committed by Junio C Hamano
parent 44ccb337f1
commit 39dbd49b41
4 changed files with 28 additions and 56 deletions

View File

@ -357,20 +357,6 @@ size_t strbuf_expand_literal_cb(struct strbuf *sb,
const char *placeholder,
void *context);
/**
* Used as callback for `strbuf_expand()`, expects an array of
* struct strbuf_expand_dict_entry as context, i.e. pairs of
* placeholder and replacement string. The array needs to be
* terminated by an entry with placeholder set to NULL.
*/
struct strbuf_expand_dict_entry {
const char *placeholder;
const char *value;
};
size_t strbuf_expand_dict_cb(struct strbuf *sb,
const char *placeholder,
void *context);
/**
* If the string pointed to by `formatp` contains a percent sign ("%"),
* advance it to point to the character following the next one and