Commit 26194507 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Have the VCL compiler provide a hint about the worst case number of

operations on the req.hash variable.

It is only a hint, because it merely counts how many times the parser
saw something being added to the req.hash variable.  If the operation
was in a subroutine which was called multiple times, the hint will not
reflect the number of actual operations.

For now we will deal with that at runtime, at the expense of a
failed transaction every time we run short.  If this becomes an issue,
an extensive topological analysis of the VCL program can give us
a definitive count.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@1803 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 17a55cb0
......@@ -26,6 +26,8 @@ struct VCL_conf {
const char **srcname;
const char **srcbody;
unsigned nhashcount;
void *priv;
vcl_init_f *init_func;
......
......@@ -209,6 +209,12 @@ parse_set(struct tokenlist *tl)
return;
}
Fb(tl, 0, ");\n");
/*
* We count the number of operations on the req.hash
* variable, so that varnishd can preallocate the worst case
* number of slots for composing the hash string.
*/
tl->nhashcount++;
break;
case STRING:
if (tl->t->tok != '=') {
......
......@@ -348,6 +348,7 @@ EmitStruct(const struct tokenlist *tl)
Fc(tl, 0, "\t.nsrc = %u,\n", tl->nsources);
Fc(tl, 0, "\t.srcname = srcname,\n");
Fc(tl, 0, "\t.srcbody = srcbody,\n");
Fc(tl, 0, "\t.nhashcount = %u,\n", tl->nhashcount);
#define VCL_RET_MAC(l,u,b,n)
#define VCL_MET_MAC(l,u,b) \
Fc(tl, 0, "\t." #l "_func = VGC_function_vcl_" #l ",\n");
......
......@@ -83,6 +83,7 @@ struct tokenlist {
struct proc *mprocs[N_METHODS];
unsigned recnt;
unsigned nhashcount;
};
enum var_type {
......
......@@ -338,6 +338,8 @@ vcl_output_lang_h(struct vsb *sb)
vsb_cat(sb, " const char **srcname;\n");
vsb_cat(sb, " const char **srcbody;\n");
vsb_cat(sb, "\n");
vsb_cat(sb, " unsigned nhashcount;\n");
vsb_cat(sb, "\n");
vsb_cat(sb, " void *priv;\n");
vsb_cat(sb, "\n");
vsb_cat(sb, " vcl_init_f *init_func;\n");
......
......@@ -142,6 +142,8 @@ puts $fo { unsigned magic;
const char **srcname;
const char **srcbody;
unsigned nhashcount;
void *priv;
vcl_init_f *init_func;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment