Save a few cycles and simlify code.
Use apr_pstrmemdup instead of apr_pstrndup when possible.
Avoid scanning the first 2 bytes when looking for the | delimiter. it is known to be "${".
Avoid comma separated statements, it is not that usual.
@@ -687,7 +687,7 @@ static meta *metafix(request_rec *r, const char *buf, apr_size_t len)
p = buf+offs+pmatch[1].rm_eo;
while (!apr_isalpha(*++p));
for (q = p; apr_isalnum(*q) || (*q == '-'); ++q);
- header = apr_pstrndup(r->pool, p, q-p);
+ header = apr_pstrmemdup(r->pool, p, q-p);
if (!ap_cstr_casecmpn(header, "Content-Type", 12)) {
ret = apr_palloc(r->pool, sizeof(meta));
ret->start = offs+pmatch[0].rm_so;
@@ -744,27 +744,26 @@ static const char *interpolate_vars(request_rec *r, const char *str)
const char *replacement;
const char *var;
for (;;) {
- start = str;
- if (start = ap_strstr_c(start, "${"), start == NULL)
+ if ((start = ap_strstr_c(str, "${")) == NULL)
break;
- if (end = ap_strchr_c(start+2, '}'), end == NULL)
+ if ((end = ap_strchr_c(start+2, '}')) == NULL)
break;
- delim = ap_strchr_c(start, '|');
+ delim = ap_strchr_c(start+2, '|');
/* Restrict delim to ${...} */
if (delim && delim >= end) {
delim = NULL;
}
- before = apr_pstrndup(r->pool, str, start-str);
+ before = apr_pstrmemdup(r->pool, str, start-str);
after = end+1;
if (delim) {
- var = apr_pstrndup(r->pool, start+2, delim-start-2);
+ var = apr_pstrmemdup(r->pool, start+2, delim-start-2);
}
else {
- var = apr_pstrndup(r->pool, start+2, end-start-2);
+ var = apr_pstrmemdup(r->pool, start+2, end-start-2);
}
replacement = apr_table_get(r->subprocess_env, var);
if (!replacement) {
