Some substitutions require pretty expensive operations. So it makes sense to find out which are needed to begin with. Call interp_find_active() to set the new "active" field in the interpolation table. Signed-off-by: Johannes Schindelin <johannes.schindelin@xxxxxx> --- This is the patch that Rene proposed, but squashed into my earlier patch. interpolate.c | 20 ++++++++++++++++++++ interpolate.h | 3 +++ 2 files changed, 23 insertions(+), 0 deletions(-) diff --git a/interpolate.c b/interpolate.c index 6ef53f2..bbd89bb 100644 --- a/interpolate.c +++ b/interpolate.c @@ -102,3 +102,23 @@ unsigned long interpolate(char *result, unsigned long reslen, *dest = '\0'; return newlen; } + +void interp_find_active(const char *orig, + struct interp *interps, int ninterps) +{ + char c; + int i; + + for (i = 0; i < ninterps; i++) + interps[i].active = 0; + + while ((c = *(orig++))) + if (c == '%') + /* Try to match an interpolation string. */ + for (i = 0; i < ninterps; i++) + if (!prefixcmp(orig, interps[i].name + 1)) { + interps[i].active = 1; + orig += strlen(interps[i].name + 1); + break; + } +} diff --git a/interpolate.h b/interpolate.h index 77407e6..d23531a 100644 --- a/interpolate.h +++ b/interpolate.h @@ -14,6 +14,7 @@ struct interp { const char *name; char *value; + int active:1; }; extern void interp_set_entry(struct interp *table, int slot, const char *value); @@ -22,5 +23,7 @@ extern void interp_clear_table(struct interp *table, int ninterps); extern unsigned long interpolate(char *result, unsigned long reslen, const char *orig, const struct interp *interps, int ninterps); +extern void interp_find_active(const char *orig, + struct interp *interps, int ninterps); #endif /* INTERPOLATE_H */ -- 1.5.3.5.1597.g7191 - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html