Commit 7fe9889a authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Optimize the compiled code by generating static const gethdr_s's

parent d445e56a
......@@ -838,9 +838,9 @@ for i in sp_variables:
if len(i[2]) == 0:
fo.write('\t NULL,\t/* No reads allowed */\n')
elif typ == "HEADER":
fo.write('\t "VRT_MkGethdr(req, HDR_')
fo.write('\t "HDR_')
fo.write(i[0].split(".")[0].upper())
fo.write(', ",\n')
fo.write('",\n')
else:
fo.write('\t "VRT_r_%s(req)",\n' % cnam)
fh.write(ctyp + " VRT_r_%s(const %s);\n" % (cnam, i[4]))
......@@ -849,9 +849,9 @@ for i in sp_variables:
if len(i[3]) == 0:
fo.write('\t NULL,\t/* No writes allowed */\n')
elif typ == "HEADER":
fo.write('\t "VRT_SetHdr(req, VRT_MkGethdr(req, HDR_')
fo.write('\t "HDR_')
fo.write(i[0].split(".")[0].upper())
fo.write(', ",\n')
fo.write('",\n')
else:
fo.write('\t "VRT_l_%s(req, ",\n' % cnam)
fh.write("void VRT_l_%s(%s, " % (cnam, i[4]))
......@@ -861,7 +861,6 @@ for i in sp_variables:
fh.write(ctyp + ", ...);\n")
restrict(fo, i[3])
fo.write('\t 0,\n') # XXX: shoule be NULL
fo.write("\t},\n")
fo.write("\t{ NULL }\n};\n")
......
......@@ -205,8 +205,6 @@ struct var {
unsigned r_methods;
const char *lname;
unsigned w_methods;
const char *http;
const char *hdr;
};
struct method {
......
......@@ -33,6 +33,7 @@
#include <string.h>
#include "vcc_compile.h"
#include "vct.h"
/*--------------------------------------------------------------------*/
......@@ -42,8 +43,10 @@ vcc_Var_Wildcard(struct vcc *tl, const struct token *t, const struct symbol *wc)
struct symbol *sym;
struct var *v;
const struct var *vh;
int l;
int l, i;
char c;
char buf[258];
char cnam[256];
vh = wc->var;
......@@ -55,14 +58,27 @@ vcc_Var_Wildcard(struct vcc *tl, const struct token *t, const struct symbol *wc)
v->r_methods = vh->r_methods;
v->w_methods = vh->w_methods;
v->fmt = vh->fmt;
v->http = vh->http;
/* Create a C-name version of the header name */
l = strlen(v->name + vh->len) + 1;
for (i = 0; i < l - 1; i++) {
c = *(v->name + vh->len + i);
if (vct_isalpha(c) || vct_isdigit(c))
cnam[i] = c;
else
cnam[i] = '_';
}
cnam[i] = '\0';
/* Create the static identifier */
Fh(tl, 0, "static const struct gethdr_s VGC_%s_%s =\n",
vh->rname, cnam);
Fh(tl, 0, " { %s, \"\\%03o%s:\"};\n",
vh->rname, (unsigned)l, v->name + vh->len);
bprintf(buf, "\\%03o%s:", (unsigned)l, v->name + vh->len);
v->hdr = TlDup(tl, buf);
bprintf(buf, "%s\"%s\")", vh->rname, v->hdr);
bprintf(buf, "&VGC_%s_%s", vh->rname, cnam);
v->rname = TlDup(tl, buf);
bprintf(buf, "%s\"%s\"), ", vh->lname, v->hdr);
bprintf(buf, "VRT_SetHdr(req, %s, ", v->rname);
v->lname = TlDup(tl, buf);
sym = VCC_AddSymbolTok(tl, t, SYM_VAR);
......
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